i just started programming in python and am just getting the hang of it myself. one of the things i like to do to gain a little confidence when i first start with a new language is to make a simple calculator. it uses alot of basic things to get you going like, user input, if statements, and printing. its useful to get a feel for the syntax.

anyways, i have been wanting to make a tutorial for a while and thought this would be a great opportunity.

for a calculator, there are a few basic things that you are going to want to do

1. present the user with a menu to select a type of operation.
2. read the user input
3. get the numbers that the user wants to use
4. perform an operation using the input from the user
5. print the results

well doing the first part is pretty easy. in python to print you simply use

btw the \n is simply an escape sequence that drops the following text to the next line.

for our second step we must get the users input. this can be done using:

variable = raw_input('string that prompts the user for what you want')

in our particular situation we want to convert the input to an integer, we can do this like so:

#prompts user for input and saves the values to variables
operation = int(raw_input('What type of operation would you like to do?\n'))
first_number = int(raw_input('Please enter your first number to be computed\n'))
second_number = int(raw_input('Please enter your second number to be computer\n'))

the next step is to perform a certain operation to the two numbers that the user inputs, but it has to correlate to the operation that they selected from our menu. this can be achieved using if statements

if statements in python are pretty simple. they consist of the word 'if', a condition, a colon, and then what you want to do if the condition is satisfied. it looks something like this:

if operation == 1:
print first_number * second_number

so the rest of our if statements are pretty much common sense and when done they look like this: