Programming Examples - Python

These are programs that I've written as demonstrations of particular programming techniques or types of solution for both KS3 Computing and GCSE Computer Science.  They are organised by technique/concept.  There are further examples in the Python course and Microtips playlist on the Computing and ICT in a Nutshell YouTube channel.

The sections are:

NB. Some examples appear twice (possibly with different descriptions) because they use multiple techniques, and some examples with similar names might approach the same problem in different ways.

Repetition with For

Repetition with While

Nested Loops

Lists and Tuples

Multi-Dimensional Lists

Dictionaries

Character/String Manipulation

Boolean Logic

Random Numbers

Modular Arithmetic (and other Mathematical Techniques)

Sorting

Number Bases

Compression Techniques

Drawing with Turtle

Reading and Writing Files

Recursion

Object-oriented Methods

Larger Programs/Projects

You'll notice that I tend to use lists or tuples in my code to avoid the need for multiple IFs - I explain the technique in this article, and also demonstrate how it can be used to improve a common Magic 8 Ball program here.  You can also make use of True and False to avoid the need for a lot of IFs in your code.  Finally, there is a video on recursion, in which I explain how the factorial, palindrome and prime factorisation programs work.

If you prefer to use a local IDE, you can download programming examples in BASIC, JavaScript and Python.

* These programs are also solutions to OCR Coding Challenges.