Operation Early Finish

You've finished the course. Now the doors are locked and only code will open them. Solve puzzles in Python, check your answers with check.py, collect stars.

How it works. Write a program that prints the answer. Then run check.py, type the puzzle ID (e.g. B1) and your answer. Every puzzle has a small example you can test your code on first. Do all of Bronze, then as much of Silver and Gold as you can. After 3 wrong answers you get a hint.

Bronze

Everybody finishes these. No files needed.

B1The coffee run

Mr Docherty needs caffeine to survive the afternoon. He buys 4 coffees at £2.35 each and 3 bacon rolls at £1.90 each, and pays with a £20 note.

Your task: Write a program that works out his change. Use variables for the prices and quantities.

Test your code on this first: 1 coffee and 1 roll paid for with a £5 note gives change of 0.75.
Answer format: Money to 2 decimal places, e.g. 3.25
Skills: variables, arithmetic, output

B2Fire drill sums

The fire alarm goes off and the door lock only opens for the right number. The rule on the sign: add up every whole number from 1 to 300 that is a multiple of 6 or a multiple of 8.

Your task: Use a loop and MOD to build the total. (Numbers that are multiples of both are only counted once.)

Test your code on this first: From 1 to 20 the numbers are 6, 8, 12, 16, 18 → total 60.
Answer format: A whole number
Skills: fixed loop, MOD, selection with OR

B3The late bell

The bell is stuck. It only rings on a number that is a multiple of 7 but not a multiple of 5. How many of the numbers from 1 to 500 make it ring?

Your task: Count them with a loop and an IF using AND.

Test your code on this first: From 1 to 40, the multiples of 7 are 7, 14, 21, 28, 35 — but 35 is also a multiple of 5, so the answer is 4.
Answer format: A whole number
Skills: loop, running count, selection with AND

B4Vowel lock

The Computing corridor door is voice locked. It needs the number of vowels (a, e, i, o, u, capital or not) in this sentence:
Cover teachers are heroes who never get thanked enough

Your task: Store the sentence in a variable and count the vowels with a loop. Don't count by hand!

Test your code on this first: Hello World has 3 vowels.
Answer format: A whole number
Skills: string traversal, upper/lower case, running count

Silver

Reading files and handling data.

S1Attendance audit

Mr Docherty has found the class test scores in data/scores.txt (60 scores, one per line).

Your task: Read the file and find the highest score, the lowest score and the average (to 1 decimal place).

Test your code on this first: Scores 40, 90, 65, 20, 85 → 90-20-60.0
Answer format: highest-lowest-average, e.g. 90-20-60.0 (spaces don't matter)
Skills: reading a file, 1-D array, max, min, average

S2Password patrol

The IT office has dumped 80 passwords into data/passwords.txt. A password is valid if it has at least 8 characters, at least one digit, at least one capital letter and no spaces.

Your task: Count how many of the 80 passwords are valid.

Test your code on this first: Tiger2024 is valid. tiger2024 (no capital), Tiger (too short, no digit) and Tiger 2024 (has a space) are not.
Answer format: A whole number
Skills: validation, functions, counting

S3Locker lottery

150 lockers and their 4-digit combinations are in data/lockers.csv (lines look like L001,4821).

Your task: Count how many lockers have a combination that contains the digit 7 at least once.

Test your code on this first: Combinations 1234, 7071, 5555, 1707 → 2
Answer format: A whole number
Skills: reading a file, splitting strings, counting occurrences

S4Tuck shop takings

The tuck shop has written its week into data/tuckshop.csv (item, price in pence, number sold). The first line is a heading.

Your task: Which item made the most money (price × number sold)?

Test your code on this first: crisps 60p × 10 = 600, juice 90p × 8 = 720, bar 45p × 15 = 675 → juice
Answer format: The item name in lower case, e.g. juice
Skills: parallel arrays, find the maximum

Gold

Real problem-solving. Be prepared to think.

G1The speech

Mr Docherty wrote a long, rambling speech, saved in data/speech.txt. Somebody has to find its most overused word.

Your task: Find the most common word. Ignore capital letters and punctuation, and ignore any word of 3 letters or fewer.

Test your code on this first: The lion saw the other lion. Lions! → lion-2 (the and saw are too short to count, and lions is a different word from lion).
Answer format: word-count, e.g. lion-2
Skills: string handling, dictionaries or parallel arrays, algorithm design

G2Secret message

An encrypted message is in data/secret.txt. It was locked by shifting every letter forward by 7 places (A→H, B→I … and it wraps round, so T→A).

Your task: Decrypt it. The passphrase is hidden in the message.

Test your code on this first: OLSSV decrypts to HELLO
Answer format: The passphrase in lower case
Skills: ASCII codes, modular arithmetic, string building

G3Prime suspects

The final door only opens for prime numbers.

Your task: How many prime numbers are there below 5000, and what is the largest one?

Test your code on this first: Below 20 the primes are 2, 3, 5, 7, 11, 13, 17, 19 → 8-19
Answer format: count-largest, e.g. 8-19
Skills: nested loops, efficient algorithm design

G4Minefield

data/board.txt is a 16 × 16 minesweeper board: * is a mine, . is a safe square.

Your task: Each safe square shows how many of its (up to 8) neighbours are mines. Work out the number for every safe square and give the total of all of them.

Test your code on this first:
*..
...
..*
gives 6 (the middle square shows 2).
Answer format: A whole number
Skills: 2-D lists, nested loops, boundary checking