Creating the Times Tables Program
Now we’re going to show you how to make a program that generates multiplication tables. For example, if the user requests a multiplication table for the number 7, it outputs the sequence
21, and so on. The program is only a few lines long, but it teaches you how to create programs, how to use variables to store numbers, how to ask the user for information, and how to create sections of program that repeat (loops). You’ll build on your understanding of the
Creating and running your first Python program
The problem with entering instructions in the shell is that you have to enter them each time you want to use them. The commands are carried out straight away, too, which limits the sophistication of the kinds of things you can do. You can solve these problems by creating a program, a set of repeatable instructions that you can save as a file and use again.
To create a program, you use script mode, which is a blank window when you open it, but otherwise looks like Figure 12-2. To open the script mode window, click the File menu at the top of the Python shell, and then click New Window.
When you enter commands in script mode, they’re not carried out straight away. The window acts like a simple text editor, and enables you to enter your list of commands (or program), and gives you control over when those commands are carried ...