Raspberry_Pi_Education_Manual

Notes:

Lesson 3.1: Getting to grips with Python

From the menu on your desktop, you should be able to find “Programming” and then “Idle3”. Select this to open up a special Python editor for creating Python programs, called “IDLE”. If you cannot find it, press ALT-F2 and then type “Idle3” in the box that appears.

The first thing IDLE gives you is a “ Python Shell ”. Snakes don’t have shells but if Python were a nut, this would be its shell.

Now press the Return key a few times and you’ll see that “>>>” appears at the start of each line. That is called the “ prompt ”. The prompt is Python’s way of telling you it is waiting for you to give it some instructions. Prompts are used in lots of computer-science applications when the computer is waiting for you.

Firstly, you need to type in some commands at the prompt to make your Python shell do something. So type this (don’t type the prompt >>>):

>>> w = 20 >>> print (w)

This will show you the number 20 in the shell window. “w” is a variable that you have set to the value 20. Then you print that value on the output.

Let’s use “w” in a more interesting way. Try this:

>>> w = 20 >>> for i in range (w): print ( ">" + " " *(w-i)+ "." *i*2+ " " *(w-i)+ "<" )

Use IDLE’s “print” function to create this pyramid.

Press Return twice. Now, that’s a little more impressive. If you want, you can change “w” by typing:

>>> w = 35

Experiments in Python

73

Made with FlippingBook flipbook maker