Python at CodeClub

Today William (11) and Henry (13) joined a group of kids helping CodeClub find out ways of possibly teaching the Python programming language in Primary school after-school clubs, in addition to Scratch.

Drawing fractals in Python at CodeClub

Scratch is a very kid-friendly graphical environment for learning some basic concepts of writing code. Python, however, is a real programming language. It is not fluffy. It forces you to use the command line. Eeek!

Python testing at CodeClub

Quite a challenge to make it child-friendly, but I think the approach they adopted was a good one: they start with using the turtle library to draw shapes and patterns on the screen that will be instantly familiar to any child who has used Scratch, Logo or any kind of programmed turtle.

Learning how to make cyphers in Python at CodeClub

Children migrated from typing Python instructions at the command line, to using IDLE to edit and save their code; I think we agreed it would be better to dive straight into IDLE. (Half way through the day I finally figured out why IDLE is called IDLE. Doh!).

Python testing at CodeClub

They moved from drawing lines, to polygons, writing their own functions to draw shapes with different parameters and then using these functions to make different patters or pictures on the screen, drawing robots or geometric designs. Kids who wanted to could then plug their laptops into the big screen and show everyone else what they’d achieved.

Henry demoing his Python code at CodeClub

Thanks to everyone at CodeClub for their work today, and for Mozilla for being such lovely and generous hosts.

Trying Python at home

Here’s my bit of code I knocked up this evening using some of the concepts we looked at today, and including some new ones, such as random numbers and lists.

What it does is define a function called shape that has 2 parameters: the size of the shape, and the number of sides the polygon it draws will have. The speed command makes it draw a bit faster (this would have been handy earlier today when William was drawing polygons with 1000 sides!). It then draws polygons in random colours with increasing numbers of sides – from triangles to octagons.

from turtle import *
import random

reset()

def shape(size,sides):
    for n in range(sides):
        forward(size)
        right(360/sides)

speed(300)

colours = ["red","orange","yellow","green"]

for x in range(3,9):
    randomcolour = random.randint(0, 3)
    pencolor(colours[randomcolour])
    pensize(5)
    shape(50,x)

Some things to note:

In lists, the 1st item in the list is actually item number 0 in Python, so my random number to pick a colour from the list is between 0 and 3, not between 1 and 4.

I’m making shapes with different numbers of sides using a for loop – I don’t want a 1 or 2-sided shape, so I am starting my counting loop at 3 – hence for x in range(3,9): – also note that this counts from 3 to 8 – not 9. Crazy, eh?

I had a few problems running IDLE in MacOS X 10.6 – it kept hanging. I had to install some extra software and update Python. There’s more info here: http://www.python.org/getit/mac/tcltk/ – once I’d done that, all I have to do is type ‘idle’ at the OS X command line to launch IDLE.

This entry was posted in computers and tagged , . Bookmark the permalink.

2 Responses to Python at CodeClub

  1. Philippa says:

    Code Club is inspiring – my own 11 y.o. comes dancing out of it every week fizzing with excitment and ideas – he’s into year 2 of the club and just learning HTML, and Python is NEXT. I am so grateful to our local primary for running it, and the parent who gives up his time to teach. Cheers – P

  2. blogmywiki says:

    Fantastic. I’m hoping to be able to run my own trial Code Club at some point in the future.

Leave a Reply