Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1def ask(question, answer): | Ascore += 1 is not indented, so it is not inside the if block and Python raises an IndentationError. | |
| 2return reply == answer | BGives back True if the player's reply matches the answer, otherwise False | |
| 3Add 1 to the score each time the player gets a question right | Cscore = 0 is inside the loop, so the score resets to 0 on every question and the total is lost. | |
| 4Show the final score after the loop ends using an f-string | DDefines a function that takes a question and its correct answer as parameters | |
| 5if ask(q, a): score += 1 | Eif ask(q, a): score += 1 | |
| 6for q, a in questions: score = 0 if ask(q, a): score += 1 | Fprint(f"You scored {score}") |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
if ask(q, a): score += 1 — Calls a function that returns True for a right answer, then adds 1 to score when it does. Put this in a loop to ask every question and total the quiz score.def ask(question, answer):
return input(question) == answerdef ask(q, a):
return input(q) == afor q, a in quiz:
if ask(q, a):
score += 1score = 0
for q, a in quiz:
if ask(q, a): score += 1print(f"Score: {score}/{len(quiz)}")