W WolfCode · CSC 141

Letter Grade

等级字母

≈ 15 min · python-conditionals · Open in WolfCode

Same elif chain as the example — but with five branches and an order-of-branches trap that bites almost everyone the first time.

Specification

Implement letter_grade(score):

  • score >= 90"A"
  • score >= 80"B"
  • score >= 70"C"
  • score >= 60"D"
  • score < 60"F"

The trap

What does this return for score = 95? Predict first.

The fix: order high-to-low

Python · runnable

Check yourself

Read Think Python §5.5 again if this surprises you.

With the BROKEN ordering above, letter_grade(95) returns:

Now you try in WolfCode

Open 01-letter-grade.py and write the correct version. The autograder checks all 8 cases including 90, 60, and 59 (boundaries). The Tutor is enabled at L1–L3 — L4 is off by design.