I was recently asked about a way to introduce beginners to programming. This was to be used in my school during “discovery days”, when high-school students come to visit and see what await them.
An introduction to programming
After some discussions about what this introduction should look like, we had come to the following points :
- It should be graphical and interactive, so to provide an immediate way of visualising what you’re doing ;
- It should use a high level language, so there is no need of introducing “complicated” low-level concepts ;
- It should be easily translatable, because it is a French school and it is easier for some students who don’t speak english.
We finally decided to go with an implementation of the LOGO language (a pointer on the screen that you can move with simple instructions) written in Python.
Python was an obvious choice, because it is a very high-level language and so very easy to understand for beginners. A simple and readable syntax and no need to type variables.
So, what I have done is basically an interface for calling graphical methods and a wrapper so that you can simply put your instruction in a file and don’t bother with the environment around. Another advantage of Python here is that you can launch the program with an interpreter and play, in an interactive manner, with the program.
The functions provided are very simple and allow to go forward, turn, change the brush color and size. A file is also provided with translations of all theses functions names in French, and it is easy to translate toward another language.
For example, drawing a square could look like :
Drawing a spiral is also quite simple, the following code also change the color :
angle = 2
n = 3500
for i in range(n):
# compute a new color
c = int(i * 255. / n)
change_color((100, c, 50))
# draw the line and slightly change the angle
angle *= 0.9995
We also provided a simplified, one-button, version of the PyScripter IDE. The goal was really that the students were not bothered by technicalities.
But despite this apparent simplicity it is possible to learn all the programming basics, from variables to recursion. What we taught during the small practical we organized (1h30) was the following :
- What is programming? Why program?
You can download the project on GitHub.
The students that participated in theses practicals had no experience in programming but quickly managed to draw simples then more complicated shapes on the screen. Most of them were enjoying the activity and at the end of each of the three practicals about half of the students asked to get their code send to them by email.
So, it was good to see that this project was appreciated and maybe gave to some the will to learn more.