Comparison Operators for Grade Bands

Medium ⏱ 12 min 49% acceptance ★★★★☆ 4.2
Write a function letter_grade(score) that maps a numeric score (0-100) to a letter grade using comparison operators: "A" for 90 and above, "B" for 80-89, "C" for 70-79, "D" for 60-69, and "F" below 60.

Examples

Example 1
Input
letter_grade(95)
Output
'A'
Explanation

95 >= 90.

Example 2
Input
letter_grade(82)
Output
'B'
Explanation

80 <= 82 < 90.

Example 3
Input
letter_grade(55)
Output
'F'
Explanation

Below 60.

Constraints

  • score is an int from 0 to 100.

Topics

Operatorscomparison operators

Companies

DeloitteAccentureCapgemini

Hints

Hint 1

Chain if/elif from the highest band downward, using >= comparisons.

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