$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · easy · #246

Which fix removes the bug?

score = 95
if score >= 50:
    grade = 'pass'
elif score >= 90:
    grade = 'distinction'
print(grade)  # expected distinction
  1. Change the elif to else
  2. Test >= 90 first, then >= 50
  3. Use > instead of >=
  4. Add break after the 'pass' line
Only the first true branch of an if/elif chain runs. 95 >= 50 matches first, so the stricter test must come before the looser one.
Play Problem Solving ▸