Making Decisions with if

~8 mincode completion

Write letter_grade(score) that turns a score out of 100 into a letter:

scoregrade
90 or above"A"
80 to 89"B"
70 to 79"C"
below 70"F"

The boundaries are inclusive at the bottom: 90 is an A, 89 is a B.

Examples

95 is comfortably an A

Input
letter_grade(95)
Output
"A"

90 exactly is still an A, the boundary is inclusive

Input
letter_grade(90)
Output
"A"

89 falls to a B

Input
letter_grade(89)
Output
"B"

Hints

Hint 1

Work directly with the arguments score and return the result rather than printing it.

Hint 2

Watch for this: boundary off by one.

Requirements

  • score: a number from 0 to 100

  • Return "A", "B", "C" or "F"

Constraints

  • Standard library only, no imports required

  • Time limit: 200 ms, Memory: 64 MB

Where this shows up

~8 min

3 employers weight this skill

2 frontier labs, 1 AI product company. Top match scores 80.

Python
def letter_grade(score):
    """
    Convert a numeric score to a letter grade.

    Args:
        score: a number from 0 to 100

    Returns:
        "A", "B", "C" or "F"
    """
    # YOUR CODE HERE
    pass
Loading docs…

The AI Mentor needs an account

It reads your code and the failing tests and nudges you toward the fix without handing you the answer. Free accounts get it on every problem you're working on today.