Lesson 25 of 30

Lesson 25 ? Mini quiz app

Title: Ask questions and count points

Description: Build a quiz with questions, answers, conditions, and a score.

Why it matters for kids: Quizzes are great practice for input, strings, and if statements.


1. One question

pythonpython
answer = input("What color is the sky on a clear day? ")

if answer.lower() == "blue":
    print("Correct!")
else:
    print("Good try.")

2. Add score

pythonpython
score = 0
answer = input("What is 2 + 2? ")

if answer == "4":
    score = score + 1

print("Score:", score)

3. Three questions

pythonpython
score = 0

if input("3 + 1 = ") == "4":
    score = score + 1

if input("5 - 2 = ") == "3":
    score = score + 1

if input("2 * 3 = ") == "6":
    score = score + 1

print(f"You got {score} out of 3.")

4. Store questions in a list

pythonpython
questions = [
    ["2 + 2", "4"],
    ["3 + 3", "6"],
]

for question in questions:
    print(question[0], "answer is", question[1])

5. Easy examples

pythonpython
answer = "Python"
print(answer.lower())
pythonpython
score = 2
print(f"Final score: {score}")
pythonpython
is_correct = True

if is_correct:
    print("Point added!")

6. Mini challenge

Click each example to open it.

Example 1

Ask one math question.

Example 2

Check if the answer is correct.

Example 3

Create score = 0.

Example 4

Add 1 point for a correct answer.

Example 5

Ask three tiny questions.

Example 6

Print final score.

Example 7

Use lower for a word answer.

Example 8

Store one question in a list.

Example 9

Store two questions in a list.

Example 10

Create a five-question quiz.