This is the old 1st edition. The new 2nd edition of "Invent Your Own Computer Games with Python" is located at http://inventwithpython.com
Let's make another program. Open a new window by clicking on the File menu at the top and then clicking on New Window. (And remember to not type the numbers at the beginning of each line. Those are only to make the source code more readable here.)
favorites.py
- # Favorite stuff
- print 'Tell me what your favorite color is.'
- favoriteColor = raw_input()
- print 'Tell me what your favorite animal is.'
- favoriteAnimal = raw_input()
- print 'Tell me what your favorite food is.'
- favoriteFood = raw_input()
- # display our favorite stuff
- print 'You entered: ' + favoriteFood + ' ' + favoriteAnimal + ' ' + favoriteColor
- # print 'Here is a list of your favorite things.'
- print 'Color: ' + favoriteColor
- print 'Animal: ' + favoriteAnimal
- print 'Food: ' + favoriteFood
Save this program as favorites.py and then press F5 to run it.

This program looks similar to our Hello World program. Let's look at each line carefully.
- # Favorite stuff
This is another comment. The program will ignore it. It's just there to remind us what this program does if we look at the source code later.
- print 'Tell me what your favorite color is.'
Here we display a bit of text asking the user to type in their favorite color by using the print keyword.
- favoriteColor = raw_input()
Now we are going to call the raw_input() function to let the user type in their favorite color. When they press enter, the string the user entered is stored in the favoriteColor variable.

- print 'Tell me what your favorite animal is.'
- favoriteAnimal = raw_input()
These two lines are similar to the ones before. Notice that there is a blank line in between them. In the Python language, blank lines are just ignored. This is helpful because then we don't have to have all the lines bunched together.
This time, the user will type what their favorite animal is, and the string will be stored in a variable named favoriteAnimal.
- print 'Tell me what your favorite food is.'
- favoriteFood = raw_input()
Finally, we will let the user type in their favorite food. This string is stored in yet another variable called favoriteFood.

- # display our favorite stuff
Here's another comment. Comments don't always have to go at the top of the program. They can show up anywhere. All the text after the pound sign (#) will be ignored by the program and won't be shown to the user. It just reminds the programmer what the program does.
- print 'You entered: ' + favoriteFood + ' ' + favoriteAnimal + ' ' + favoriteColor
This print statement will show us the favorite food, animal, and color we entered. The plus sign is used to combine the string 'You entered: ' with the strings we stored in our variables earlier. We don't want the strings in the variable to be bunched together, so we add a string with one space in between them. This will make the entire string look something like this:
'You entered: pasta cats blue'
Instead of this:
'You entered: pastacatsblue'
- # print 'Here is a list of your favorite things.'
This line looks like another print statement. But do you see the pound sign at the start of it? That means this line is really a comment and the program ignores this code. Sometimes the programmer may want to remove code from the source code with the intent to add it back in later. Instead of deleting the code, you can just put a pound sign to have it ignored for now. If you delete the pound sign, then this code will no longer be a comment and would be executed with the rest of the program. In IDLE, you can easily see that this is a comment and not code because it is in red text.
- print 'Color: ' + favoriteColor
- print 'Animal: ' + favoriteAnimal
- print 'Food: ' + favoriteFood
These three lines will display our favorite things once again. When the last line of the program executes, the program terminates.
The computer doesn't really care what you type in. It doesn't understand what food or animals or colors are. All it knows is that the user will type in some string. We don't have to type in our favorite things at all. Look at this run of the program where I type in some crazy answers:

All the program understands is that it should store the string the user enters into the variables and display the string in those variables later on.

The program also does not care what name we give to our variables. Our program would work just the same if it looked like this:
favorites2.py
- # Favorite stuff 2
- print 'Tell me what your favorite color is.'
- q = raw_input()
- print 'Tell me what your favorite animal is.'
- fizzy = raw_input()
- print 'Tell me what your favorite food is.'
- AbrahamLincoln = raw_input()
- # display our favorite stuff
- print 'You entered: ' + q + ' ' + fizzy + ' ' + AbrahamLincoln
- #print 'Here is a list of your favorite things.'
- print 'Color: ' + q
- print 'Animal: ' + fizzy
- print 'Food: ' + AbrahamLincoln
The names we give the variables are more for our benefit than the computer's benefit. One name looks the same as any other to the computer. The name q doesn't help us remember that this variable is supposed to store the string of the user's favorite color. And the name fizzy isn't any type of animal. And using the name AbrahamLincoln for the variable to store our favorite color is just silly. But since we use the variables in the same way as before, the program works the exact same.
Have you noticed that variable names that are made up of more than one word have the other words capitalized? This is to make the variable names easier to read because variable names can't have spaces in them.
thisnameiskindofhardtoread
thisNameIsEasierToRead
Leave the first word in lowercase, but start the other words in uppercase. We call something in a certain way like this a convention: we don't have to do it this way, but doing it this way makes it a little easier. The convention for capitalizing variable names is to leave the first word in lowercase but start the other words in uppercase.
Remember, the computer doesn't care how we name our variables. It only cares how we use them in the program. Look at this program:
favorites3.py
- # Favorite stuff 3
- print 'Tell me what your favorite color is.'
- q = raw_input()
- print 'Tell me what your favorite animal is.'
- AbrahamLincoln = raw_input()
- print 'Tell me what your favorite food is.'
- AbrahamLincoln = raw_input()
- # display our favorite stuff
- print 'You entered: ' + q + ' ' + AbrahamLincoln + ' ' + AbrahamLincoln
- #print 'Here is a list of your favorite things.'
- print 'Color: ' + q
- print 'Animal: ' + AbrahamLincoln
- print 'Food: ' + AbrahamLincoln
When we run this program, it looks like this:

What happened here? The favorite animal and favorite food are the same thing. If you notice, we use the same variable named AbrahamLincoln to store a string of our favorite animal and our favorite food. When the user typed in their favorite animal, this string was stored in the AbrahamLincoln variable. But when the user typed in their favorite food, this string was also stored in the AbrahamLincoln variable and the favorite food string was forgotten. The favorite food value was overwritten. The computer can't tell the difference between them because they use the same name. So the computer thinks we mean to use the same variable.

A variable can only store one value at a time.
The computer will do exactly what we tell it to do, even if we tell it to do the wrong thing. The computer can't read our minds and figure out what we want it to do. It is up to the programmer to make sure the program works just right.
As a final note about variable and function names, I should tell you that the computer does pay attention to the capitalization of the name. The computer considers these names to be four separate variables:
fizzy
Fizzy
FIZZY
fIzZy

Four differently-cased names means four different variables.
We call this case-sensitivity. In the Python language, variable and function names are case-sensitive. If you try to call the RAW_INPUT() function instead of the raw_input() function, you will get an error because the computer doesn't know of a function named RAW_INPUT(). It only knows a function named raw_input().
So remember that even though the computer doesn't care what you name your variables or how you capitalize them, be sure to always use the same capitalization. It is also a convention to never use two different variables with the same name but different capitalization. If you use the variable favoriteFOOD to store the string of your favorite breakfast food and the variable FAVORITEfood to store your favorite dinner food, it is easy to forget which is which.
You don't always have to finish typing in a program before you run it. You can just have some of the code complete, and then run it just to see how the program behaves. Programmers will often type some code, run the program, type some more code, run the program again, and so on in order to make sure the code is coming along the way they like. You can also always use the interactive shell to type single lines of code in to see what it does.
Now that we have some of the basics down, in the next chapter we will create our first game!
Things Covered In This Chapter:
- Case-sensitivity
- Conventions