Lesson 90 +50 XP

Project 8: Quiz Game

Project 8: Quiz Game

A simple quiz that asks questions from a list of dicts and scores the answers.

The goal

Store questions and answers, ask each one, and print the final score.

What you practice

  • Lists of dictionaries
  • Loops
  • Comparison
  • Input handling

Starter code

questions = [
    {"question": "What is 2 + 2?", "answer": "4"},
    {"question": "What color is a banana?", "answer": "yellow"},
    {"question": "How many days in a leap year?", "answer": "366"}
]

score = 0

for q in questions:
    reply = input(q["question"] + " ")
    if reply.lower() == q["answer"].lower():
        print("Correct!")
        score += 1
    else:
        print("Wrong!")

print(f"Score: {score}/{len(questions)}")

Step-by-step

  1. Run the starter and answer the questions.
  2. Add two more questions of your own.
  3. Accept answers with different capitalization.
  4. Add a multiple-choice option list to each question.

Checklist

  • [ ] Questions come from a list of dicts
  • [ ] Answers are compared correctly
  • [ ] The score counts right answers
  • [ ] Case doesn't break answers
  • [ ] The final score prints

TL;DR

  • A list of dicts organizes each question.
  • lower() on both sides fixes capitalization.
  • score += 1 counts correct answers.