My First Raspberry Pi Game – Part 02 – Saying hello

Parts: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12.

Writing your first ever computer program on the Raspberry Pi. See Part 1 for how to get and set up the Pi.

Today we will find out how to write a computer program, and how to run it.

We’re going to write one of the simplest programs you can write – we’re going to get the computer to say hello to us.

First, we need a text editor to write down our program. Click the weird aeroplane-y thing in the bottom left – that brings up the menu (like the Start button on Windows), then choose Accessories, then Leafpad. Leafpad is the text editor we will be using.

Leafpad will start, and show you an empty page. This is where we will write our program.

Type in exactly this:

print "Hello, world!"

and then click the File menu at the top of the Leafpad window and choose Save As. Click the word “pi” on the left and then click in the empty box next to the word Name, and type the name of our program, which is:

redgreen.py

“redgreen” is the name and the “.py” means this is a program written in the language Python. We’ll be finding out more about Python as we go on.

Click the Save button.

Our program is finished! Now we need to run it.

Click the aeroplane-y thing again, then Accessories, then LXTerminal. A terminal is a program you use to run other programs.

When LXTerminal has started, your cursor will appear next to a $ sign. This means it is ready for you to tell it what to do.

Type exactly this:

python redgreen.py

What this means is run the program called “python”, and pass the name of our program (redgreen.py) to it. This is how you run Python programs.

Now press the RETURN key.

If all goes well, our program will talk back to us, and say what we told it to say:

Hello, world!

Let’s look again at our program.

It’s just one “statement”, a print statement. A statement is something to do.

We pass one “argument” to print, “Hello, world!”. An argument is some information you give to a statement.

“print” doesn’t mean print to the printer, but write to the screen. So our program did exactly what we told it to do – it wrote our message to the screen.

Next time, we’ll map out the whole of our real program – a simple game.

Update: congratulations to sparkboy123 on getting this working!

One thought on “My First Raspberry Pi Game – Part 02 – Saying hello”

  1. Hi Andy.
    I decided to do the exercises. I found out that they don’t work with python 3. But as you mentioned in the comments on the previous chapter, it works fine with python 2. I did another mistake -in case anyone else does the same-. I used uppercase. So, things did not work until I used lower case for the command and for the name of the file. Thanks for the videos and the tutorial.

Leave a Reply

Your email address will not be published. Required fields are marked *