Hardware Reference
In-Depth Information
way to Scratch. In this tutorial, you use the turtle module as an introduction to writ-
ing code in Python.
In Adventure 5, you will get a more thorough introduction to the Python program-
ming language, the IDLE programming environment, and Python functions and mod-
ules. In this adventure, you can just follow along with the instructions, and you will
begin to see how the Scratch blocks correspond to Python coding.
For a video that walks you through using the Python interface to type commands,
visit the companion website at www.wiley.com/go/adventuresinrp . Click
the Videos tab and select the PythonIntro ile.
Introducing Python Modules
As you learn more about programming and continue to write code, you will discover
that many of the programs you write include similar tasks and require similar blocks of
code. To avoid the necessity of rewriting the same code over and over, most program-
ming languages include reusable blocks of code, called modules . Python has a large
number of modules containing useful code that you can reuse. You will learn more
about modules in Adventure 5.
In this adventure, you use the Python turtle module to create graphics.
The IDLE Environment and the
Interpreter Window
To use Python, you need access to the programming environment IDLE 3. To open
IDLE 3, double-click the IDLE 3 icon on the desktop of your Raspberry Pi, or click on
the main menu and select Programming IDLE 3, as shown in Figure 4-9. You can
type commands directly into the IDLE window after the prompt, which is represented
by three >>> characters. You type a line of code and then press Enter to run it. his
window is referred to as an interpreter (or a shell ), as it understands the language you
are using, in this case Python, and interprets the code one line at a time.
You will learn more about the IDLE and IDLE 3 programming environments in the
next adventure.
Search WWH ::




Custom Search