LessonΒ·difficulty 1/5Β·~10 min
Conditionals: letter grades
Read the task β edit your code β Run to see the output β Run tests to check your answer.
Conditionals
Decisions in code use if, elif, and else:
python
if temperature > 30:
advice = "Drink water."
elif temperature > 15:
advice = "Light jacket."
else:
advice = "Bundle up."
The first branch whose condition is True runs. elif is short for
"else if" and there can be as many as you need. else is optional but
catches everything else.
Your task
Write a function grade(score) that takes an integer 0β100 and returns
the matching letter grade as a string:
| Score range | Returns |
|---|---|
| β₯ 90 | "A" |
| 80 β 89 | "B" |
| 70 β 79 | "C" |
| 60 β 69 | "D" |
| anything else | "F" |
Example:
python
grade(95) # "A"
grade(72) # "C"
grade(40) # "F"
Tests
- 100 -> A
- 90 -> A
- 85 -> B
- 70 -> C
- 65 -> D
- 0 -> F
β¦ Need help with this task?
Sign in or create a free account to get AI help. Free includes a monthly AI allowance.
warming up
Loading editorβ¦
Consolewaiting
$ Console output will appear here.