Learn to Program in Python

This is a set of free resources aimed at helping students learn to program in Python. The course was createted for KS3 Computing classes, but could be used for GCSE Computer Science or for self-study or revision in conjunction with the Python playlist on the Computing in a Nutshell YouTube channel. Once you have mastered the basics you can develop your skills with the practice tasks.

Note that the lessons refer to "programming" - I don't like the term "coding" because it suggests that syntax is more important than decomposition, and because "coding" has other meanings in relation to databases and encryption and could confuse students.

Computational Thinking

The real reason that we teach programming in schools is not to provide vocational training for the software industry, but to give students a grounding in general problem solving skills that they can apply in non-programming contexts.  This is called computational thinking.  For each task they are given, I encourage them to consider that:

We can apply these ideas to a simple program, e.g. if asked to print the two-times table, then we wouldn't just print 2, 4, 6, 8, etc., we'd think about how those answers are generated, count from 1 to 12, multiplying by two as we went along.  It's essentially the same as any counting program, e.g. Ten Green Bottles (see below).  If we stored the 2 in a variable and used that to multiply, then we could easily generalise the program to display other tables.  Using a for loop wouldn't really make the program more efficient (in the sense that it wouldn't be quicker or use less memory), but it would be more concise.

We can also apply this to non-programming tasks, e.g. making a web-page.  Thinking about the structure is more important than the appearance - how does a rollover work; how do we make a drop-down menu, etc?  Could we make a page that appears equally well on all devices (by using a fluid layout and a careful choice of fonts)?  Could we improve the page by using efficient file formats, minimising the use of unnecessary images and http requests, etc?

Key Programming Concepts

Below are links to presentations explaining the key programming concepts. I have written an article describing my top ten programming techniques for older students, but these are the ones that I start with at KS3. I have also created a presentation containing tips on how to become a more confident programmer. They also include code examples in BASIC or Python.

You might also want to cover general programming ideas such as:

Programming Tasks for Beginners

Here are some of the programming challenges that students could approach to begin with - there are versions of most tasks for BASIC and Python:

Most tasks have extensions, and we encourage students to enhance their programs beyond the bare minimum, where possible.

If you enjoy attempting tasks like these, then why not register for Project Euler or the Ubuntu Forums for some more challenges?

Examples

I have created a set of Python examples organised by programming technique/construct, which I use to demonstrate concepts to students of KS3 Computing and GCSE Computer Science.

Solutions to the Tasks

Many of the programs on the examples page are also solutions to these tasks.

Programming the Curriculum

Why not link with other areas of the new Computing National Curriculum by getting your students to create programs to demonstrate, or test their understanding of key Computing concepts? You can create programs for converting numbers from denary to binary (using bitwise Boolean logic or otherwise) or binary to denary, for sorting and searching, to demonstrate encrpyion techniques, bitwise manipulation, compression with Run-Length Encoding, Huffman Coding or dictionary compression, or to help them think about the storage of text by capitalising text or creating anagrams. You can find all of these, plus Turtle examples and more on the Python examples page or in the downloadable .zip file of examples.

Finally... Python is very, very slow.  If you compare my Sudoku solving program written in JavaScript and Python, using this 17-clue puzzle from Wikipedia, then (on my computer) the JavaScript version running in the Edge browser takes about 50 seconds, the Visual Basic version takes about a minute, but the Python version (interpreted locally with py.exe rather than in Basthon or IDLE) takes 36 minutes!

There is also a set of examples available on my examples page and, finally, I'm maintaining a list of programming practice tasks and slowly working my way through the OCR Coding Challenges.

JavaScript Examples

There is no JavaScript course, but I have created a zipped file of JavaScript examples that can be used to demonstrate key techniques to students, particularly changing text and colours on the page to display state. Examples include choosing lottery numbers, a traffic light, a die model, a seven-segment display, a Simon game, a Sudoku solver and rotation. There are also more generic examples in the JavaScript section of this site, and examples of how you can add animation to web-page without using any JavaScript at all.

Video Courses

I am developing video courses on how to learn to program on the Advanced ICT YouTube channel:

For older students I have also written articles on the use of modular arithmetic, using arrays for selection, creating functions and object-oriented programming in Python as well as my top ten programming techniques and a page on recursion. There is also a Python guide for GCSE (aimed at OCR as it contains some ERL).