──────────────────────────────────────

36. The Repair Bench · Repair a Broken Quiz

Reproduce a scoring bug, fix it and cover varied input with repeatable checks.

Lesson files · lessons/debugging-and-tests/repair-a-quiz

Before you start
- Clean text with strip() and lower().
- Use if, elif and else to choose one result.
- Run a failing case and inspect its result.

By the end
- Use a repeatable input to reproduce and check a bug fix.
- Use a check for empty text after cleaning the reply.
- Test a spaced correct answer, a blank answer and a wrong answer.

Where you can use it
Fix a spelling quiz that rejects an answer with extra spaces. Save that exact reply and try it again after the change.

Run the starter with ORBIT surrounded by spaces. Write down the expected output and what actually appears. Clean the reply with strip() and lower(), then run that exact input again to check the fix.

Spaces alone become an empty string after strip(). The condition if not answer is true when answer is empty. Put that case first, then check the answer key and handle any other reply. Try a blank answer and a wrong one as well as the repaired case.

Predict
What should happen when the answer is blank?
- It is marked correct.
- It gets an explicit response.

Worked example (example.py)

answer = input().strip().lower()
print(answer == "orbit")


Example input
 ORBIT 

Example result
True

Read one answer to the quiz. Trim and lowercase it. Print No answer. if empty, Correct! if it is orbit, and Try again. for any other answer.

Starter program (starter.py)

answer = input()
if answer == "orbit":
    print("Correct!")
else:
    print("Try again.")


Starter input
 ORBIT 

Hint
Use if not answer for the blank case before checking answer == "orbit".

Case 1. Try the sample
Input
 ORBIT 
Expected output
Correct!

Case 2. Blank answer
Input
   
Expected output
No answer.

Case 3. Wrong answer
Input
comet
Expected output
Try again.

Project checklist
Run the sample case.

Project checklist
Try one different case and explain what happened.

Marking criterion
Program behaviour (4 points)
Each required behaviour works on the supplied cases.

Marking criterion
Use of the lesson concept (3 points)
The code uses the main idea in a clear, purposeful way.

Marking criterion
Test evidence (2 points)
The reflection describes a case, its expected result and what happened.

Marking criterion
Explanation (1 points)
The learner explains a change or design decision in their own words.

Stretch
Write two assertions for a separate clean_answer(text) function.

Reflect
What was the first input that proved the starter had a bug?

Check your prediction
It gets an explicit response. A blank answer means the player has not supplied an answer. Detect it before comparing.
