KS 2: Starting with Python 1

opengraph-icon-200x200Computers can use different languages to communicate just as people do.  These are called programming languages and enable us to talk to the computer if we know the language it uses to carry out our instructions. This is a first lesson in using a language called Python.

Some languages are called after the people that invented them, for example Pascal or Ada.  Other languages are acronyms such as BASIC and FORTRAN.

Why Python?

The programme we are going to learn is Python. This wasn’t named after the snake but after the TV comedy programme Monty Python’s Flying Circus.

Python is a good first language to learn as it uses proper code (unlike Scratch, which uses ‘blocks’), it does not use complicated symbols such as {  }  or # or $ , which are common in other languages, and it is fairly quick to learn.

Installing Python

The first thing you will have to do is install Python on your machine.  How you do it will depend on whether you are using Windows or Mac OS X and which version of each you are running.  We have put up some tutorials to show you how to do this.  Click here for Mac, click here for Windows. (This tutorial is actually for Windows 8. If you have an older version, just search on YouTube!)

Python exists in two versions, Python 2 and Python 3.  Mac OSX has Python 2 already installed but we recommend that you install Python 3 if you are going to use our posts. (There are not that many differences – just enough to make it confusing!). Whatever you do, don’t delete Python 2 – keep both. (The reason is that some bits of the Mac OS uses Python 2 to make certain things work)

After you have installed it, go to the Python 3 icon in your applications folder.  Ignore everything except the icon that says IDLE and put that on your desk top.  IDLE, by the way, is an acronym for Integrated Development and Learning Environment – basically this is the place you are going to write your code. It is a ‘text editor’ if anyone is interested.

pythonFirst Programme

When you open IDLE ( i.e click on it) you should get quite a boring looking screen something like this.  The black print at the top tells you that you are now working in the Python environment. If you get a blue WARNING message, ignore it. Your computer is not about to blow up.

The first thing you need to do is write and run a very simple program to make sure that the installation was fine and everything so far is working properly.

The program that everyone uses as a test just tells the computer to say Hello world!  You have probably seen this before. This is how you do it in Python.

Hello World!

hello worldType into the IDLE screen the following

print(“Hello, world”)

then press return!  You should get something that looks like this.

The great thing about Python is that you get different colours for different things so it is very easy to read.

You have just written your first program – you told the computer to print Hello, world! and it did. You might want to explain that print, in this context, does not mean printing on paper but writing on the screen.

If you get it wrong, you will be told in a red message that you have a syntax error. If you get a syntax error, you won’t be able to delete it but that’s fine, just do it again underneath. The computer will ignore your first attempt because it won’t understand it!

Linking to natural language

Once all the children have got that far, ask them to describe the differences between the input (the line of code in purple and green) and the output (words written in blue). For example, one has brackets and inverted commas, the other doesn’t. It helps if you have large cards with the code written on one and the output on another that you can pin on the wall.

You might also want to link this to a grammar lesson and point out that brackets and inverted commas exist in human language. What do they mean in English? What do they think they mean in Python? You could also ask what part of speech the word outside the brackets is? Print describes the action you want the computer to take – like a verb. It appears in purple.

Let the children practice telling the computer to print other things, using the same syntax.

Next Steps

Once you have done this, you are ready to move on to writing a longer programme.  You can find this in Starting with Python 2.  We have made this a separate post so that the posts were not too long. However, you can probably do both in a single lesson.



jen hughes

View my other posts

Leave a Reply

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