Letter Grade

Easy · rating 1000 · Implementation

Read an integer test score from 0 to 100 and print its letter grade: A for 90–100, B for 80–89, C for 70–79, D for 60–69, and F below 60.

Editorial

Approach

Check the thresholds from highest to lowest and return at the first one the score clears. Ordering the checks top-down means each condition only needs a single lower bound.

x = int(input())
if   x >= 90: print('A')
elif x >= 80: print('B')
elif x >= 70: print('C')
elif x >= 60: print('D')
else:         print('F')

Complexity

Time: O(1). Space: O(1).

Related problems

Open Letter Grade in Code Arena →