Friday, March 20, 2009

The raw_input() Command

This command tells the computer to wait for user input before continuing. So if you write,

print 'hello world'
raw_input('press enter to continue')
print 'goodbye'

It would print, "hello world" and wait until you press enter to continue, then print "goodbye"

You can also put input into variables. For example, if you want to make a variable "name" and have it ask for a name, you write:

name = raw_input('what's your name?')

Press enter to insert what you typed into the variable.

To make it print the name you typed in, write:

print name

This prints what you have entered as your name.

Next post : else, if and then commands





Wednesday, March 4, 2009

Variables

Variables are a very important part of the python programming language.

They work very much like variables in algebra. You can set anything not used by python as a variable.

For example, using a as a variable works because it is not already a command. You can also use more than one letter, like abcdefg as a variable.

Making variables is easy. Just type:

abcd = 4

This is just an example. You can use almost any variable name, as long as it isn't used by python. so "print" is a bad variable name, but "print_object" could work.

You can also set the variable to words, not just numbers. For example:

abcd = 'example'

Just make sure to put the quotation marks around the text.

Next Post : raw_input()

Tuesday, March 3, 2009

Your First Program

The first program that is usually written by a beginning python programmer is a program that writes "hello world" on the screen.

This program is very simple. Type:

print 'hello world'

Then save and run it. It will show "hello world" on the screen.

The print command tells the computer to write whatever is in quotations after the command.

The one rule is that the text you want to print must be in quotes. You can use single or double quotes as long as you end with the same type of quote.

So you can't type, "hello world' or 'hello world"
.

But 'hello world' and "hello world" will work,

Next Post: Variables

Download python

To download the python programming tools, click here.

Open the python folder, and you will see several applications.
The application IDLE or IDE depending on which version you are using, is the interpreter.
Type commands there for it to execute them.
If you go to file > New Window you will get a blank page.
This is where you will type your longer scripts with several lines.

The window that comes up automatically is the interpreter. Type scripts there to see if they work but you can only put one line at a time, so use the new window to write scripts.

To execute the script, save them (File > Save) and execute them (Run > Run Module) or F5. The window with the scripts must be selected for you to see the run option.

Next post : Your First Program!

Tuesday, February 24, 2009

Welcome!

Here I plan to teach anyone who would like to listen how to write simple programs using python. If you want more or have questions, email me at marwan.kallal@gmail.com.

Thanks,
qwertyfreak