Lazo Lab Sign up

App 1: Your First App, a Quiz Game / Build the quiz

Lesson 6 of 10

Multiple choice

Store choices too, number them, and let the player type a number. Use a dictionary per question so the code stays readable.

Key points

  • A dict per question: text, choices, answer
  • enumerate(choices, start=1) numbers them
  • Compare the chosen number
questions = [
    {"text": "Which port does HTTPS use?", "choices": ["80", "443", "22"], "answer": 2},
]

for q in questions:
    print(q["text"])
    for i, choice in enumerate(q["choices"], start=1):
        print(f"  {i}. {choice}")
    pick = input("Your choice: ").strip()
    if pick == str(q["answer"]):
        print("Correct!")

Your turn

Turn three of your questions into multiple choice.

Watch a video on thisOpens YouTube search results for “Multiple choice” in a new tab

Quiz · +10 XP

In the example, which number must the player type to be right?

Log in to save progress and earn XP.