๐Ÿ PyQuest๐Ÿ† Game: Quiz Show Champion ยท ๐Ÿ” Step 3: Loop the Questions
โญ 0 XP๐Ÿ Python is waking upโ€ฆ

Step 3: Loop the Questions ๐Ÿ”

Look at your code from Step 2. The same if/else block, copied three times. Want 10 questions? Copy it 10 times? No thanks. ๐Ÿ™…โ€โ™€๏ธ

Programmers have a rule: if you're copying, you should be looping.

Put the questions in one list and the answers in another, in the same order:

questions = ["Capital of France? ", "6 times 7? "]
answers   = ["paris", "42"]

Question 0 goes with answer 0, question 1 with answer 1. Now loop over the positions with range(len(questions)):

for i in range(len(questions)):
    reply = input(questions[i]).lower().strip()
    if reply == answers[i]:
        print("โœ… Correct!")

len(questions) is how many questions there are, so i counts 0, 1, 2... and questions[i] grabs the one at that position. One block of code, as many questions as you like. ๐Ÿคฏ

Your mission

  1. Make a questions list and an answers list (at least 3 each)
  2. Loop with for i in range(len(questions)):
  3. Keep the score going inside the loop
  4. Print the final score after the loop ends

โš ๏ธ Watch your answers: store them lowercase so .lower() matches!

Your code

Press โ–ถ Run to see what your code does!