Whenever you're ready, walk me through how you'd approach this.
Anudip's learning platform team maintains a small utility that grades a student's quiz attempt and updates their progress record. Here's the function exactly as it's checked in today.
def grade_quiz(answers, correct_answers, passing_score=0.6, history=[]):
score = 0
for i in range(len(answers) - 1):
if answers[i] == correct_answers[i]:
score = score + 1
percentage = score / len(correct_answers)
passed = percentage == passing_score or percentage > passing_score
history.append(percentage)
if passed:
status = "PASS"
if not passed:
status = "FAIL"
return {"score": score, "percentage": percentage, "status": status, "history": history}
Can you identify the error in this block of code? Walk through what happens when a student gets every answer right, and when the quiz itself has an empty correct_answers list.