Stories You Can Interact With

rushabh meha python workshopRushabh Mehta.

This is a summary of what happened in the third programming class for kids at Shishuvan. 

The first computer program you are generally taught in first year of engineering is a function that returns the factorial of a number. Factorial? Who uses factorials? What are they used for? We usually have no idea or any emotional connect to that problem. No wonder most find computer programming boring!

The conventional thinking is that computer programming is closely related to math and logic. The heart of a computer consists of hexadecimal numbers, flashing through transistors at lightening speed, and hence the reason that programming must be taught like math.

There is an alternate way to approach programming. Donald Knuth, who wrote the classic “Art of Computer Programming”, considered to be the bible of computer science, talks about “Literate Programming”, where programming is considered as a natural language, and not a mathematical algorithm. This means that programming can also be taught as literature and not just mathematics.

Jump start

In the first class we did variables, functions and lists and almost everyone got what we did, in the second class, we did more complex functions, using lists and loops and also introduced the concept of Python modules. Again most of the kids who attended, got this. Some kids understood a lot more than others.

In this class, we had many kids who had not attended the second class, so they were coming after a gap of two weeks and needed to be jump started. So we spent quite some time recapping what we did in the last class and quite a few kids could write the functions we wrote almost form memory. So far so good. It was a good revision for the kids who had attended both the classes.

At the end of the second class, we had decided that in the next class, we were going to make a sorting hat, a hat from the Harry Potter books that separates students into groups

Sorting hat

So I asked the kids, how does the sorting hat work? One of the kids came up with this answer, “When a student wears a sorting hat, the hat matches the student’s abilities with the abilities of the founder of the house. And which ever ability matches the most, the student is assigned to that house”. Pretty good explanation!

So we said, lets start making a sorting hat.

houses = ["Gryffindor", "Slytherin", "Ravenclaw", "Hufflepuff"]
abilities = ["bravery", "cunning", "intellegence", "hard-work"]

Yeah, mmm, this was good, two lists, but the next question is how do we co-relate the houses to abilities? Here is where we introduced classes

class House:
    ability = None
class Student:
    ability = None
gryffindor = House()
gryffindor.ability = 'bravery'
harry = Student()
harry.ability = 'bravery'

We saved this file as and went into the Python shell. This was a good time to introduce inspection and the Python function dir, which helps you explore objects.

>>> import sortinghat
>>> dir(sortinghat)
['House', 'Student', '__builtins__', '__doc__', '__file__', '__name__', '__package__', 'gryffindor', 'harry']

Here we imported the sortinghat module and looked at what was inside it. We found a few things we recognized, Student, House, harry and gryffindor. Then we looked inside gryffindor

>>> dir(sortinghat.gryffindor)
['__doc__', '__module__', 'ability']

We found ability! Then we knew what this was:

>>> sortinghat.gryffindor.ability

Now that we understood what classes were, we added a few more properties like name and created a list of all the houses and students.

Let play

After that we decided to move straight to the magic. Click here to view the full file.

def sort(student):
    for house in all_houses:
        if house.ability == student.ability:
            if house.students is None:
                house.students = []
            print + ' goes to ' + + '!'

Then reloaded the module and called the function sort

>>> reload(sortinghat)
>>> sortinghat.sort(sortinghat.harry)
Harry Potter goes to Gryffindor!

We made a sorting hat!

Again a flurry of questions and the kids were eager to try it themselves. This was quite a long program and there were bound to be issues. Most kids got confused with the forced indentation in Python and a whole lot of them struggled. But at the end of it there were three or four who could get this working.


At the end of the third class, it seemed most of the kids were struggling, especially those who had missed the second class. There were too many concepts thrown at them and while they were having fun and trying hard, there was more assimilation that needed to be done.

On the other hand it was heartening that there were four or five kids who were getting it. These are kids who had never learned how to program but could understand a whole lot of concepts to get a program working. Now is the time to consolidate learning. In the next class, we will try and make more variations to this model and reinforce what we already know.

In Harry Potter we have found a great analogy to learn programming. Kids love stories and if they can feel they are writing one, it would be a great leap of imagination. How well they go from here will depend on what kind of support they find at their homes. I am hoping at least some of these kids have supportive parents / guardians who can help them make that leap.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>