Page 33 - Programming the Raspberry Pi Getting Started with Python
P. 33
Figure 3-4 Creating a Python folder
Next, we need to switch back to our editor window and save the file using the File menu. Navigate
to inside the new Python directory and give the file the name hello.py, as shown in Figure 3-5.
Figure 3-5 Saving the program
To actually run the program and see what it does, go to the Run menu and select Run Module. You
should see the results of the program’s execution in the Python Shell. It is no great surprise that the
program prints the two words Hello and World, each on its own line.
What you type in the Python Shell does not get saved anywhere; therefore, if you exit IDLE and
then start it up again, anything you typed in the Python Shell will be lost. However, because we saved
our Editor file, we can load it at any time from the File menu.
NOTE To save this book from becoming a series of screen dumps, from now on if I want you to type
something in the Python Shell, I will proceed it with >>>. The results will then appear on the lines
below it.
Numbers
Numbers are fundamental to programming, and arithmetic is one of the things computers are very
good at. We will begin by experimenting with numbers, and the best place to experiment is the Python
Shell.