Upcoming: student sessions with AI researchers, software engineers, and technology mentors.
Back to projects
PythonBeginner30–45 minutes

Math Challenge Game

A quick game that turns multiplication practice into a coding exercise. Students learn randomness, loops, arithmetic, and score tracking while producing something they can play immediately.

Starter code

Read it. Run it. Change it.

Save the code below as math_challenge.py. The example is intentionally small enough for a student to explain line by line before adding new features.

math_challenge.pyPython
import random

score = 0

for question in range(5):
    first = random.randint(1, 10)
    second = random.randint(1, 10)
    correct = first * second

    answer = int(input(f"{first} x {second} = "))

    if answer == correct:
        print("Correct!")
        score += 1
    else:
        print("The answer was", correct)

print("\nFinal score:", score, "out of 5")

How to run it on a laptop

  1. 1. Install Python 3 if it is not already available.
  2. 2. Open IDLE, Thonny, VS Code, or any simple text editor.
  3. 3. Copy the code into a new file named math_challenge.py.
  4. 4. Run the file. No internet connection, database, or server is required.

Build it step by step

1

Generate numbers

Use Python's random module to make each question different.

2

Repeat questions

Use a for loop to ask five questions.

3

Compare answers

Check the student's response against the calculated answer.

4

Show a score

Add one point for every correct answer.

Make it your own

  • Let the player choose addition, subtraction, or multiplication.
  • Add easy, medium, and hard levels.
  • Tell the player their percentage at the end.