This is the first lesson with no new syntax — just you, combining everything from lessons 1 through 6 into something real.
A quick note: our in-browser editor can't pause and wait for you to type an answer like a real terminal can, so instead of typing answers live, we'll store the player's answers in a list ahead of time and have the program check them. Real quiz apps often work exactly this way — answers collected first, checked after.
Read it slowly — every piece is something you already know:
- a list of dictionaries holds the questions and correct answers (lesson 5)
- a function
run_quiztakes the quiz and the answers, and runs it (lesson 6) - a for loop with
enumerategoes through each question (lessons 4 & 5) - an if/else checks whether the answer matches (lesson 3)
- a variable
scorekeeps count, updated each time around the loop (lesson 2)
Nothing here is new. This is what programming actually looks like — small ideas, stacked.
Your turn
Write your own 3-question quiz about something you know well — a game, a show, a sport. Change the questions, answers, and try giving yourself a wrong answer on purpose to see the "Nope" message.
Next lesson: saving things permanently, by reading and writing files.