TalentJR

🐍 Python for kids · Class 5 · Lesson 18 of 18 · Free

Capstone Projects – Quiz, Guessing Game & Report Card

⏱ About 35 minutes · ▶ run real Python here — nothing to install · no sign-in

In this lesson you will

  • Plan a project in small steps before writing any code.
  • Build a quiz game and a number guessing game with loops and functions.
  • Make a report card that uses a dictionary, functions and a file.

You have learnt variables, loops, lists, dictionaries, functions, errors and files. That is like collecting all the parts of a bicycle. Today you put the parts together and ride! You will build three real programs from start to end.

How do I plan a Python project?

Every good project starts on paper, not on the keyboard. Ask three questions: What goes in? What does the program do? What comes out?

Next, list the small jobs, and give each job a function. Then build one piece at a time, and run it after every piece.

Small steps mean small mistakes. They are much easier to find and fix.

🐍 Python — you can edit this code
Output
Plan done. Let's build it!

Project 1: How do I build a quiz game?

The function ask() asks one question and checks the reply. It returns 1 for a correct answer and 0 for a wrong one.

strip() removes extra spaces and lower() ignores capital letters. So "New Delhi" and "new delhi" both count as correct.

Adding the returned values gives the score. Watch the two calls run one after the other.

🎬 How Python thinks — step 1 of 12Python is about to run line 1
▶def ask(question, answer):
2 reply = input(question + " ")
3 if reply.strip().lower() == answer:
4 print("Correct!")
5 return 1
6 print("Oops! The answer is", answer)
7 return 0
8
9score = ask("Capital of India?", "new delhi") + ask("7 x 8 = ?", "56")
10print("Score:", score, "out of 2")
📦 Variables (memory boxes)

No variables yet.

🖥️ Output
▌
✏️ Change this code and run it yourself
🐍 Python — you can edit this code
Output
Capital of India? New Delhi
Correct!
7 x 8 = ? 54
Oops! The answer is 56
Score: 1 out of 2

How can I add more quiz questions easily?

Writing one line per question gets long. Instead, keep the questions and answers in a dictionary.

A for loop goes through the dictionary and calls ask() for each question. To add a question, you add just one line to the dictionary.

At the end, an if statement gives a message that depends on the score.

🐍 Python — you can edit this code
Output
National animal of India? Tiger
Correct!
How many players in a cricket team? 11
Correct!
Largest planet? Saturn
Oops! The answer is jupiter
You scored 2 out of 3.
Good try! Play again to score more.

Project 2: How do I build a number guessing game?

The computer keeps a secret number, and the player guesses. After each guess, the program says "Too high" or "Too low".

Here the secret is fixed at 37, so you can test the game easily. A while loop keeps asking until the guess is right.

The variable tries counts the guesses. Fewer tries means a better player!

🐍 Python — you can edit this code
Output
Guess a number from 1 to 100: 50
Too high!
Guess a number from 1 to 100: 25
Too low!
Guess a number from 1 to 100: 37
You got it in 3 tries!

💡 Ask a friend to change the secret number, without telling you. Then play!

Project 3: How do I make a marks report card?

A dictionary is perfect for marks: the subject is the key and the marks are the value.

The function grade() turns marks into a grade. The loop prints one line of the report card for each subject.

🎬 How Python thinks — step 1 of 18Python is about to run line 1
▶def grade(m):
2 if m >= 90:
3 return "A+"
4 elif m >= 75:
5 return "A"
6 return "B"
7
8marks = {"Maths": 92, "Science": 85, "English": 70}
9for subject in marks:
10 print(subject, marks[subject], grade(marks[subject]))
📦 Variables (memory boxes)

No variables yet.

🖥️ Output
▌
✏️ Change this code and run it yourself
🐍 Python — you can edit this code
Output
Maths 92 A+
Science 85 A
English 70 B

How do I save the report card to a file?

Now we join everything: a dictionary, two functions, a loop and a file. The report is written into report.txt and then read back.

Saving to a file means the report could be printed or shared later. On this web page, the file stays only until you close the tab.

Try changing the marks or the name, and run it again.

🐍 Python — you can edit this code
Output
REPORT CARD - Aarav, Class 5
Maths: 92 (A+)
Science: 85 (A)
English: 70 (B)
Total: 247  Average: 82.3

🤔 Predict the output

Think like Python: read the code and choose what it prints. You get the reason straight away.

Question 1. What does this print?

def check(reply, answer):
    if reply.lower() == answer:
        return 1
    return 0

print(check("TIGER", "tiger") + check("Lion", "tiger"))

Question 2. What does this print?

secret = 20
for guess in [10, 30, 20]:
    if guess < secret:
        print("Low")
    elif guess > secret:
        print("High")
    else:
        print("Win")

Question 3. What does this print?

marks = {"Hindi": 80, "EVS": 90}
total = 0
for s in marks:
    total = total + marks[s]
print(total / len(marks))

🧩 Your challenge

Upgrade the guessing game. The secret is 42. Give the player only 5 tries, and use try/except so typing a word does not crash the game (and does not use up a try). The inputs typed for you are 50, forty, 30 and 42.

Expected output (with the inputs given):
Guess: 50
Too high
Guess: forty
Numbers only!
Guess: 30
Too low
Guess: 42
You win in 3 tries!
🐍 Python — you can edit this code

⚠️ Common mistakes (and how to fix them)

❌ Wrong

secret = 37
guess = 0
while guess != secret:
    guess = input("Guess: ")
print("You got it!")

No error message — the program never stops (press Stop).

✅ Right

secret = 37
guess = 0
while guess != secret:
    guess = int(input("Guess: "))
print("You got it!")

input() gives the text "37", which never equals the number 37, so convert it with int().

❌ Wrong

answers = ["tiger", "11"]
replies = ["tiger", "11"]
for i in range(2):
    score = 0
    if replies[i] == answers[i]:
        score = score + 1
print("Score:", score)

No error — but it prints Score: 1 instead of 2, because score is reset to 0 every round.

✅ Right

answers = ["tiger", "11"]
replies = ["tiger", "11"]
score = 0
for i in range(2):
    if replies[i] == answers[i]:
        score = score + 1
print("Score:", score)

Set the score to 0 once, before the loop, so the points keep adding up.

❌ Wrong

marks = {"Maths": 92, "Science": 85}
print(marks["maths"])

KeyError: 'maths'

✅ Right

marks = {"Maths": 92, "Science": 85}
print(marks["Maths"])

Dictionary keys must match exactly, including capital letters.

📌 Remember

  • Plan first: input, process, output, and one function for each job.
  • Build one small piece at a time, and run it after every piece.
  • A quiz game uses a function that returns 1 or 0, so the score is a simple sum.
  • A guessing game uses a while loop, a counter and if/elif hints.
  • A report card joins a dictionary, functions, a loop and a file.
  • try/except keeps your game running when the player types something unexpected.

Finished the quiz and the challenge?

Questions students ask

Why is the secret number fixed instead of random?

A fixed number makes the game easy to test, because it behaves the same every time. Later you can learn the random module to make a new secret number each game.

My project does not work. What should I do?

Read the error message from the bottom line up. Then test each function alone with simple values. Adding a print() to show a variable often reveals the mistake.

What project can I build next?

Try a times-table quiz, a pocket-money tracker saved in a file, or a cricket scoreboard that keeps runs in a dictionary. Use the same plan: input, process, output.

Do I need to remember every Python command?

No. Real programmers look things up all the time. What matters is breaking a problem into steps and testing as you go.