Introducing beginners to programming with Python.

Par Sylvain, le 12 March 2012

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.

The project

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 :

for i in range(4):
    forward(100)
    turn_left(90)

Drawing a spiral is also quite simple, the following code also change the color :

def spiral():
    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
        forward(2)
        turn_left(angle)
        angle *= 0.9995

spiral()

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 :

  1. What is programming? Why program?
  2. Variables
  3. Functions
  4. Loops

Sierpinski triangles

You can download the project on GitHub.

Conclusion

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.

Keywords : , , , , , ,

Laisser une réponse


3 + 8 =