← Practice
πŸ“– ConditionalsLearning path
Browsing as guestΒ·Sign in or create a free account to save progress and use tutor tools.
LessonΒ·difficulty 1/5Β·~10 min

Conditionals: letter grades

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 rangeReturns
β‰₯ 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

✦ Stuck? Ask for a spark

Sign in or create a free account to use your monthly AI explainer allowance.

warming up
Loading editor…
Consolewaiting

$ Console output will appear here.

>_AI coach
Sign in or create a free account to chat with the tutor.