Intro: Python Tutorial
Hello! Welcome to my second instructable and this will be on the basics of python.
In this instructable, I will be teaching u the basics of loops, input and output, getting the computer to say something, if statements and variables. In the last one we will be using GUIs or graphic user interface with a tool called easygui.
Again, leave comments on how I should improve and questions on bits u don't understand
Step 1: SAY SOMETHING!
In this step, we will be learning how to make python say something. very simple. all u have to type is what u want to say, then put this around it. print (''). for example print ('hello world'). if u are using python 2 u would type print "hello world" type this into the shell window - the one that comes up and press enter.
there u go! ur first program
Step 2: This Is a Bit Loopy....
now firstly, press Ctrl+N that will get u to a new file. save it as loops.py the .py bit indicates that this is a python file. this is the first type of loop.
for i in range (1, 101):
this will go like this
the variable, i , will automatically add one each time it loops mind though, it does not print 101.
here is another loop
this is very similar to the top one. we call the top one a for loop and the bottom one a while loop.
the while loop includes the 100 so no need to do while i<101.
Step 3: Input and Output
this program will make the computer ask u something and respond to the answer.
this is an example
f=input('what's ur name')<-----------sets the variable and indicates an input
print ('hello',f)<-------------------------prints the variable which is inputted by the user with hello in front
the output should be something like this:
>>>what's ur nameLarry
as u can see the input isn't very neat. if u want a space, space the end of the first line:
f=input('what's ur name ')
if u want it to ask for ur age or how many mars bars u have, do this:
f=int(input('what's ur age'))
if its a decimal number, do:
f=float(input('enter a decimal number'))
how're u hangin' on?
Step 4: If by Rudya-----no No No! It's Python U Dimwit!
if statements are usually used to compare 2 strings or integers.
it usually comes after an input
type the program in the picture and u will be able to see how useful if can be and something u wont expect...
if *something*<,>,=,!=,<=,>=*something else*:
print (*something*'is whatever than'*something else*)
Step 5: Starter on Easygui
easygui is a module that needs to be downloaded.
download it if u don't have it then try this program.
it should come up with something like in the picture.
so that's it for now.
keep an eye open, i might do other tutorials like windows batch and other languages.
really well done that is a lot to learn!