Raspberry_Pi_Education_Manual

Notes:

So what has this to do with live Pythons? When you were typing lines of Python code to draw circles in PyGame at the start of this chapter, you were controlling the Raspberry Pi’s graphical display much like web servers are controlled by their masters. Each command is interpreted line by line, and the computer is waiting for you to tell it what to do.

Interpreting Python

Computers use instructions on the microprocessor to control them, and these are very fast but very complicated. Programming languages, such as Python, were invented to bridge the gap between how people think about problems and how a computer can process data. To keep the best performance, computers convert, or “ compile ”, the human-readable instructions into those complex computational instructions before running them. Python isn’t required to do that; although it can. By sacrificing speed, Python programs do not need to be compiled but can be interpreted line by line.

You can try this out for yourself. Open up a Linux terminal window from the menu on your desktop, you should be able to find “Accessories” and then “LXTerminal”.

Alternatively, you can press Alt-F2 and type “LXTerminal”.

Within the terminal window type:

$ python

You should see:

pi@raspberrypi:~$ python Python 3.2.2 (default, Sep 4 2011, 09:51:08) [RASPBERRY PI] Type "help", "copyright", "credits" or "license" for more information. >>>

Notice how the prompt has changed from “$” to “>>>”. This shows you that Python is active. When you want to get back to the Linux terminal, type “quit()” and press Return, but don’t do that yet. When you see the “$” prompt, you have raw access to Linux. This is described in a later chapter of this manual.

Now, at the Python prompt, type:

Tip...

>>> a = 0 >>> while (a < 10000): a+=1; print ( "Raspberry Pi Users = " , a) ...

A semi-colon (;) is used to separate two commands without pressing Return.

Experiments in Python

84

Made with FlippingBook flipbook maker