Game Development Reference
In-Depth Information
3 - Strings
When you enter your program, don't enter the numbers
at the left side of the code. They're there so we can refer
to each line by number in our explanation. If you look at
the bottom-right corner of the file editor window, it will
tell you which line the cursor is currently on.
Figure 3-2: The bottom right of the file
editor window tells you where the cursor
is. The cursor is currently on line 12.
Enter the following text into the new file editor
window. We call this text the program's source code
because it contains the instructions that Python will
follow to determine exactly how the program should behave. (Remember, don't type in the
line numbers!)
IMPORTANT NOTE! The following program should be run by the Python 3
interpreter, not the Python 2.6 (or any other 2.x version). Be sure that you have the correct
version of Python installed. (If you already have Python 2 installed, you can have Python 3
installed at the same time.) To download Python 3, go to
http://python.org/download/releases/3.1.1/ and install this version.
hello.py
This code can be downloaded from http://inventwithpython.com/hello.py
If you get errors after typing this code in, compare it to the topic's code with the online
diff tool at http://inventwithpython.com/diff or email the author at
al@inventwithpython.com
1. # This program says hello and asks for my name.
2. print('Hello world!')
3. print('What is your name?')
4. myName = input()
5. print('It is good to meet you, ' + myName)
The IDLE program will give different types of instructions different colors. After you are
done typing this code in, the window should look like this:
Figure 3-3: The file editor window will look like this after you type in the code.
Search WWH ::




Custom Search