Grade Classifier With Multiple Return Points

Easy ⏱ 8 min 77% acceptance ★★★★★ 4.9
Write a function letter_grade(score) that returns "A" for scores 90 and above, "B" for 80-89, "C" for 70-79, "D" for 60-69, and "F" below 60. Use early returns rather than nested if/else.

Examples

Example 1
Input
letter_grade(95)
Output
A
Explanation

95 >= 90.

Example 2
Input
letter_grade(55)
Output
F
Explanation

55 is below 60.

Constraints

  • score is an integer from 0 to 100.

Topics

Functionsreturn values

Companies

AccentureCognizant

Hints

Hint 1

Check the highest threshold first and return immediately when it matches.

Hint 2

Falling through to the last line means none of the earlier thresholds matched, so it must be an F.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.