Python puzzles that make you think

Keep your mind sharp in the age of AI.

Small, realistic Python puzzles, from easy to hard, that you solve by reading the code and reasoning through it, not by spotting patterns you've memorised. Fix what's broken or write it from scratch, run it in a real terminal, and keep going until the tests pass.

average.py
1 def average(scores):
2 total = 0
3 for i in range(1, len(scores)):
4 total += scores[i]
5 return total / len(scores)
6
7
8 def main():
9 assert average([2, 4, 6]) == 4
10 print("All tests passed")

➜ akone$ python3 average.py

Traceback (most recent call last):

File "average.py", line 9, in main

assert average([2, 4, 6]) == 4

AssertionError