22 programs ยท edit and run
Python programs for beginners, one idea at a time.
From printing your name to a Rubik's Cube simulator. Each page has code you can run and change, an explanation, and things to try next.
Level 1
Beginner
Hello world and variables
Print a message, store things in variables and join them together.
Ages 8+ ยท print, variablesTimes table printer
Print the seven times table with a loop.
Ages 8+ ยท for loop, rangeEven or odd
Say whether each number from 1 to 10 is even or odd.
Ages 8+ ยท if / else, remainderAdd up the numbers 1 to 100
Add 1 + 2 + 3 + ... + 100, and check the answer with a formula.
Ages 9+ ยท accumulator, for loopCountdown
Count down from 10 and finish with a message.
Ages 8+ ยท while loop, variablesTemperature converter
Turn Celsius into Fahrenheit and print a conversion table.
Ages 9+ ยท functions, returnReverse a string
Turn a sentence round in three different ways.
Ages 9+ ยท strings, slicingLevel 2
Easy
FizzBuzz
Count from 1 to 20. For multiples of 3 print Fizz, for multiples of 5 print Buzz, and for both print FizzBuzz.
Ages 9+ ยท if / elif / else, remainderFind the prime numbers
Print every prime number up to 50.
Ages 10+ ยท nested loops, breakFibonacci numbers
Build the Fibonacci sequence, where each number is the sum of the two before it.
Ages 10+ ยท lists, loopsPalindrome checker
Check whether a word reads the same forwards and backwards.
Ages 10+ ยท strings, slicingVowel counter
Count the vowels in a sentence.
Ages 10+ ยท strings, for loopA calculator with functions
Write functions for add, subtract, multiply and divide, and use a dictionary to choose one.
Ages 10+ ยท functions, parametersThe Collatz sequence
Start with any number. If it is even, halve it; if odd, triple it and add 1. See how long it takes to reach 1.
Ages 11+ ยท while loop, if / elseDecimal to binary
Turn a number into binary by repeatedly dividing by 2.
Ages 11+ ยท while loop, remainderMarks and grades
Find the total, average and grade for a list of marks.
Ages 11+ ยท lists, functionsLevel 3
Confident
Shopping basket
Add up the price of items in a basket, with quantities and a discount.
Ages 11+ ยท dictionaries, loopsRock, paper, scissors
Work out who wins each round of rock, paper, scissors from a list of moves.
Ages 11+ ยท dictionaries, functionsPascal's triangle
Print the first eight rows of Pascal's triangle, where each number is the sum of the two above it.
Ages 12+ ยท lists, nested loopsSecret code: the Caesar cipher
Send secret messages by shifting every letter along the alphabet.
Ages 11+ ยท strings, ord and chrNumber guessing game (the computer plays)
Find a secret number between 1 and 100 by always guessing the middle. See that it takes at most 7 guesses.
Ages 11+ ยท while loop, binary searchSimulate a 2ร2 Rubik's Cube move
Represent a 2ร2 cube as 24 stickers, apply the moves R and U as rearrangements, and count how many times R U repeats before the cube is solved again.
Ages 13+ ยท lists, permutationsFAQ
About these programs
Do I need to install Python?
No. Every program runs on the page in your browser. When you are ready, you can also install Python and run the same programs on your computer, because they give the same output in real Python 3.
Which program should I start with?
Start with Hello world and variables, then the times table printer and even or odd. Move on when each feels easy.
What if I get an error?
Read the message, check the line it names, and compare with the original. The debugging guide explains the six most common errors.
What age are these for?
Each program lists a starting age. The first ones suit about 8 and up. The last ones, with dictionaries and a cube simulator, suit about 12 and up.
Start a conversation
Want a teacher to guide the learning?
Tell us the learner's age and what they can already do, and we will suggest a starting point. A parent or guardian can make the enquiry.
- Tell us the learnerโs age or grade and goals
- Weโll suggest a suitable class or learning path
- Weโll confirm format, timing and fees with a parent or guardian
Play it, don't just read it
Write some code right now
Free games that need no sign-up. Pick one and play for five minutes.
Pick a game
- Predict the OutputRead a short Python program and choose what it prints. Then watch it runโฆPlay
- Bug HunterA Python program prints the wrong answer. Find the one line with theโฆPlay
- Code BuilderThe lines of a Python program are mixed up. Tap them into the rightโฆPlay
- Code JungleWrite real Python to guide Miko the monkey to every banana. 24 levels:โฆPlay