Hardware Reference
In-Depth Information
THIS PROJECT IS just a bit of fun for you to get going with your first program. The pro-
gram generates a comedy insult by combining a verb, an adjective and a noun at random. In
other words, you'll make your highly sophisticated Raspberry Pi display something like “Your
brother is a big old turnip!”
By beginning with something simple, you can start having fun without having to write too
much code, and after you've got something running, you can change it to make it more
sophisticated. In fact, professional computer programmers often take a similar approach:
They write something simple and test it, and then add more and more features, testing as
they go.
It's also useful to look at sample code, work out what it is doing and then change it to suit
your requirements. Most professional programmers work this way too. Feel free to experi-
ment and customise the projects in the topic. Just remember to keep a copy of the original
program so that you can go back to it if it doesn't work.
This appendix helps to get you started programming the Raspberry Pi and, as such, it has the
most theory in. Do stick with it, and at the end of the appendix, you'll have the knowledge to
make the program your own. There's a lot in this appendix, but you needn't do it all in one go;
sometimes it's better to come back after a break. Programming is no less creative than paint-
ing a picture or knitting, and like these hobbies, you need to spend an hour or two covering
the basics before producing a masterpiece!
In this appendix, you will learn how enter a Python program and run it. You'll also learn
about various aspects of the Python language.
Running Your First Python Program
Many people use a word processor to produce documents with a computer because it pro-
vides features such as spelling and grammar checkers. However, there is nothing to stop you
from using a simple text editor like Notepad in Windows, TextEdit on an Apple Mac or
LeafPad on the Raspberry Pi. Similarly, when writing code, you can just type it in a text editor
or you can use an Integrated Development Environment (IDE). Similar to a spell checker in a
word processor, an IDE checks the syntax (to ensure that it will make sense to the computer)
and has other helpful features to make writing code a pleasure!
Just as there are lots of different word processors, there are a number of IDEs for Python.
For the simple example in this appendix, you are going to type your first Python program
into IDLE. This is good for beginners because it is simple and can often be found wherever
Python is installed, including on the Raspberry Pi.
Search WWH ::




Custom Search