Which fix removes the bug?
score = 95
if score >= 50:
grade = 'pass'
elif score >= 90:
grade = 'distinction'
print(grade) # expected distinction
- Change the
eliftoelse - Test
>= 90first, then>= 50 - Use
>instead of>= - Add
breakafter 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 ▸