Editor

Letter Grade

#203 · Python Basics · Beginner · 25 XP · about 4 min

A teacher marks tests out of 100 and reports a letter grade. Write letter_grade(score) that returns the grade as a string:

  • 90 to 100: 'A'
  • 80 to 89: 'B'
  • 70 to 79: 'C'
  • 60 to 69: 'D'
  • 0 to 59: 'F'

A score below 0 or above 100 is a typing mistake: return 'Invalid' for it.

Examples

letter_grade(95)   # returns 'A'
letter_grade(83)   # returns 'B'
letter_grade(40)   # returns 'F'
letter_grade(120)  # returns 'Invalid'

Note

score is always a whole number.

Fastest solvers

Leaderboard

First solves only, ranked by stars and then time.