Chapter 5 Programming with Python 95
THE OFFICIAL RASPBERRY PI BEGINNER’S GUIDE
You don’t have to use Python in interactive mode, though. Click on the script area at the left-
hand side of the Thonny window, then type your program again:
print("Hello, World!")
When you press the ENTER key this time, nothing happens – except that you get a new,
blank line in the script area. To make this version of your program work, you’ll have to click the
Run icon in the Thonny toolbar. When you do, you’ll be asked to save your program first;
type a descriptive name, like ‘Hello World’ and click the Save button. Once your program has
saved, you’ll see two messages appear in the Python shell area (Figure 5-2):
>>> %Run 'Hello World.py'
Hello, World!
5 Figure 5-2: Running your simple program
SYNTAX ERROR
If your program doesn’t run but instead prints a ‘syntax error’ message
to the shell area, there’s a mistake somewhere in what you’ve written.
Python needs its instructions to be written in a very specific way: miss
a bracket or a quotation mark, spell ‘print’ wrong or give it a capital P,
or add extra symbols somewhere in the instruction and it won’t run. Try
typing the instruction again, and make sure it matches the version in
this book before pressing the ENTER key!