← All video projects

Free video project · Beginner

Build a quiz game ❓

A quiz that asks questions, accepts answers in any capitals or with stray spaces, keeps score and gives you a verdict at the end.

▶ Watch the video

The code from the video

questions = [
    ("What is 7 times 8?", "56"),
    ("What is the capital of France?", "paris"),
    ("How many legs does a spider have?", "8"),
    ("Which language are we learning?", "python"),
]

score = 0

for question, answer in questions:
    reply = input(question + " ")
    if reply.strip().lower() == answer:
        print("Correct!")
        score += 1
    else:
        print(f"Nope, it was {answer}")

print(f"You scored {score} out of {len(questions)}")
if score == len(questions):
    print("Perfect score!")
elif score >= 2:
    print("Nice work")
else:
    print("Keep practising")

Run it in your browser with nothing to install, right here on this page.

Make it your own

  1. Write ten questions about something you love and shuffle them with random.shuffle.
  2. Give two points for a first try and one for a second chance.
  3. Add multiple choice: print options A to D and accept the letter.

Skills: lists of tuples, for loops, input, string methods

Start the free lessons More video projects