Post by Azan on Mar 8, 2006 17:18:33 GMT -5
This is a small tutorial on programming with Python, the language you use for it. Note that if you are not taking this class I do not recommend going through this tutorial as I personaly hate Python, and you should only download/learn it if you are taking the class. (Python is good for beginners though, however I hate it as I am far beyond that
What you will need is Python, Python's website is www.python.org and can be downloaded for windows by clicking here.
If you have a Macintosh or Linux machine then you are in luck, Python works in both, they can be downloaded from the downloads section of their website.
Most of your work in ITCP will be done in class, however it is possible to fall behind, in which case you need python. (please note that this is really rare)...
*****************************************
Ok once you have python up and running open IDLE (python GUI)... you may hear a term like IDE alot... and alot of other terms... that is the first rule in programming always question what you dont understand.
Now moving on, you should see a screen or something similar to this...
This is the shell, or where your program output will show up, you can also enter basic commands into it for example type in...
and you should get 4.
Now hit ctrl-N or go to File then New Window, you should see something like the following...
click
This is the IDE, IDE stands for Integrated Development Environment, this is where you will type your program in, its an IDE in that certain commands that you enter will be a certain color in order to make code editing easier (dont worry, you will see examples of this later).
Now moving on, save your new window (currently its called "untitled" and the IDE wont work if its not saved. Also this is very important, whenever you save a python document or program you must save it with an extentsion of .py) now enter the following into the IDE...
"print" should turn orange, if it didnt you didnt save it or you didnt save it with an ending .py. Now first lets look at the code, its pretty simple and "print" is the easiest command you will ever learn, it simply outputs text to the screen. So this is telling python to put whatever 2+2 equals onto the screen. Now hit F5 or go to Run then Python Shell... 4 should appear on the screen.
Congrats, thats your first program.
Now we will move onto Variables, you all know what variables are, in programming they basically store forms of information, there are many different forms of information, I will go over the basic ones.
Integers - Any whole number and zero
Floats - Basicaly holds decimals
Strings - Holds text information
In some programming languages you need to declare what the variable can hold, but Python does it automatically... so run the following program to test them out, this code also shows comments, everything is explained within the code so be sure to read it.
Be sure to notice that a program is compiled from top to bottom, so obviously this causes an error as "a" doesnt exist yet...
Now once you understand that we shall move on to If statements, these are some of the most important things you will ever know as they check for if certain cases have been reached... Now python is somewhat unique in that everything within an if statement must be indented, like so, this lets python know what you want to happen within that if statement, in most other languages you do something like this...
Python uses indents (just look at the code below) this forces good coding habits as it keeps your code clean and easy to read.
www.freewebs.com/azan00/tutorial_01.txt
Well thats all I have time for at the moment, if everyone wants to I can continue these as these are only the very very basics, and dont forget to ask questions
What you will need is Python, Python's website is www.python.org and can be downloaded for windows by clicking here.
If you have a Macintosh or Linux machine then you are in luck, Python works in both, they can be downloaded from the downloads section of their website.
Most of your work in ITCP will be done in class, however it is possible to fall behind, in which case you need python. (please note that this is really rare)...
*****************************************
Ok once you have python up and running open IDLE (python GUI)... you may hear a term like IDE alot... and alot of other terms... that is the first rule in programming always question what you dont understand.
Now moving on, you should see a screen or something similar to this...
This is the shell, or where your program output will show up, you can also enter basic commands into it for example type in...
2+2
and you should get 4.
Now hit ctrl-N or go to File then New Window, you should see something like the following...
click
This is the IDE, IDE stands for Integrated Development Environment, this is where you will type your program in, its an IDE in that certain commands that you enter will be a certain color in order to make code editing easier (dont worry, you will see examples of this later).
Now moving on, save your new window (currently its called "untitled" and the IDE wont work if its not saved. Also this is very important, whenever you save a python document or program you must save it with an extentsion of .py) now enter the following into the IDE...
print 2+2
"print" should turn orange, if it didnt you didnt save it or you didnt save it with an ending .py. Now first lets look at the code, its pretty simple and "print" is the easiest command you will ever learn, it simply outputs text to the screen. So this is telling python to put whatever 2+2 equals onto the screen. Now hit F5 or go to Run then Python Shell... 4 should appear on the screen.
Congrats, thats your first program.
Now we will move onto Variables, you all know what variables are, in programming they basically store forms of information, there are many different forms of information, I will go over the basic ones.
Integers - Any whole number and zero
Floats - Basicaly holds decimals
Strings - Holds text information
In some programming languages you need to declare what the variable can hold, but Python does it automatically... so run the following program to test them out, this code also shows comments, everything is explained within the code so be sure to read it.
# Hello, im a comment, comments are used to describe what the code does
# Or to block code that could be causing errors
# These are really usefull when you get complex programs
a=-2 #integer
b=4+a #integer with a variable added
c=2.45346 # Float
d="Hello, im a string 1+1 equals 2 BTW" #this is a string,
#as you can see strings are within quotes.
print a,b #as you can see, you can print many variables on one line
print c
print d
Be sure to notice that a program is compiled from top to bottom, so obviously this causes an error as "a" doesnt exist yet...
print a
a=2
Now once you understand that we shall move on to If statements, these are some of the most important things you will ever know as they check for if certain cases have been reached... Now python is somewhat unique in that everything within an if statement must be indented, like so, this lets python know what you want to happen within that if statement, in most other languages you do something like this...
if blah=0 then
print "hi"
endif
Python uses indents (just look at the code below) this forces good coding habits as it keeps your code clean and easy to read.
www.freewebs.com/azan00/tutorial_01.txt
Well thats all I have time for at the moment, if everyone wants to I can continue these as these are only the very very basics, and dont forget to ask questions