Python
You can introduce children to simple Python coding online, free of charge. The website for this is at www.scholastic.co.uk/python and it creates a terminal. This allows us to key code in using Python coding and see the results. You will see three chevrons followed by a flashing line. This is the prompt and signifies that the program is ready for you to add code. If pupils have not seen the jam sandwich video, it is a good idea to show them this and discuss it before starting to use python. Unlike Scratch, which enables pupils to click and experiment without any prior understanding of coding, Python requires more explicit instructions. The language used is “high-level” which means it is closer to human language than some computer languages.
Now you have your prompt, you can give the program some instructions. Let’s start by engaging with the program and asking it to speak to us on screen. We use the command print for this, which means the text you ask Python to print will appear on the screen. It is important to use rounded brackets around what you want printed to separate it from the instructions you write in the program. It is important to remember that Python code is case sensitive. Ensure that you use lower case for the instruction to print.
To print numbers you need to type: print (123456789) and then press the return key to run the program.
What happened? Did the string of numbers appear?
Now try programming Python to print your name on screen. Did this work? You probably found a traceback error message telling you there was a NameError. This is because although Python recognises numbers, it doesn’t recognise words unless we put them in speech marks. This time try inputting print (“Hello your name”) and then press the return key to run the program.
Were you more successful this time? Congratulations! You have just fixed your first bug.
Did you notice that there were no chevrons before the program printed the greeting. This is because the chevrons indicate that the program is listening to the programmer for instructions rather than talking to you.
A fun program for children to create on Python is one which will tell them how many days old they are. They will need to press the return key at the end of each line of code. I have also included the chevrons, these will appear automatically on the program so you will not need to input these. You do not need a space before the brackets. If the month or date are single digit numbers input these as single digit only (e.g. March is the third month so should be inputted as 3 not 03).
>>> import datetime
>>> birthday = datetime.datetime (YYYY,MM,DD)
>>> today = datetime.datetime.now()
>>> number = (today – birthday).days
>>> print (“You are”, number, “days old”)
Could you use this program with your pupils as a guide to writing a program calculating the number of days until the end of term, Christmas, sports day or some other specific future date? The day name needs to be typed as one word (e.g. sportsday).
Remember you will need to put the date in using the year first format, identify that today = datetime.datetime.now() and swap the order within the calculation if you want to find out how many days until a future date instead of days since a past date.
Now you have your prompt, you can give the program some instructions. Let’s start by engaging with the program and asking it to speak to us on screen. We use the command print for this, which means the text you ask Python to print will appear on the screen. It is important to use rounded brackets around what you want printed to separate it from the instructions you write in the program. It is important to remember that Python code is case sensitive. Ensure that you use lower case for the instruction to print.
To print numbers you need to type: print (123456789) and then press the return key to run the program.
What happened? Did the string of numbers appear?
Now try programming Python to print your name on screen. Did this work? You probably found a traceback error message telling you there was a NameError. This is because although Python recognises numbers, it doesn’t recognise words unless we put them in speech marks. This time try inputting print (“Hello your name”) and then press the return key to run the program.
Were you more successful this time? Congratulations! You have just fixed your first bug.
Did you notice that there were no chevrons before the program printed the greeting. This is because the chevrons indicate that the program is listening to the programmer for instructions rather than talking to you.
A fun program for children to create on Python is one which will tell them how many days old they are. They will need to press the return key at the end of each line of code. I have also included the chevrons, these will appear automatically on the program so you will not need to input these. You do not need a space before the brackets. If the month or date are single digit numbers input these as single digit only (e.g. March is the third month so should be inputted as 3 not 03).
>>> import datetime
>>> birthday = datetime.datetime (YYYY,MM,DD)
>>> today = datetime.datetime.now()
>>> number = (today – birthday).days
>>> print (“You are”, number, “days old”)
Could you use this program with your pupils as a guide to writing a program calculating the number of days until the end of term, Christmas, sports day or some other specific future date? The day name needs to be typed as one word (e.g. sportsday).
Remember you will need to put the date in using the year first format, identify that today = datetime.datetime.now() and swap the order within the calculation if you want to find out how many days until a future date instead of days since a past date.
As you can see from these examples, the same mathematical symbols are used in Python as we encountered in Scratch: add (+), subtract (-), multiply (*), divide (/) and equal (=). You can use what you have learned to explore some other mathematical calculations.
Moving on: If you want to learn more about coding with Python there are some free websites which can be found easily through a search engine, although our experience was that the majority of these assumed some degree of prior knowledge. Your local library or bookshop may stock the books which we used to learn the basics. These have further ideas for activities and projects if you wish to explore Python further. |
Alternatively, you may decide that it is more beneficial for pupils to spend their coding time extending their skills with Scratch, which has been designed for use in primary schools and is highly accessible and user-friendly.
References
Carver, H. (2015) Coding Unlocked - Scratch and Python: the basics. London: Scholastic Ltd.
Roffey, C. (2012) Python Basics, Level 1: Coding Club. Cambridge University Press.
The authors are not taking ownership of any images or videos on this website, unless stated otherwise on the respective pages, and therefore have attempted to make contact with all owners of images and videos used on this website.
Roffey, C. (2012) Python Basics, Level 1: Coding Club. Cambridge University Press.
The authors are not taking ownership of any images or videos on this website, unless stated otherwise on the respective pages, and therefore have attempted to make contact with all owners of images and videos used on this website.