Editor

Build a Grade Calculator

Advanced · Write the code · from Python Functions: Define, Call, and Return Values

From the lesson: Python Functions: Define, Call, and Return Values

Imagine you have a favorite recipe for pancakes. Every Sunday morning, you follow the same steps: mix flour, crack eggs, pour batter, flip. You don't reinvent the recipe each time - you just follow the one you already know.

Read the lesson

Write a function called get_grade that takes a numeric score (0-100) and returns a letter grade as a string:

  • 90 and above: 'A'
  • 80-89: 'B'
  • 70-79: 'C'
  • 60-69: 'D'
  • Below 60: 'F'
  • # Define your function here
    # Test it
    print(get_grade(95))
    print(get_grade(83))
    print(get_grade(72))
    print(get_grade(65))
    print(get_grade(45))

    What Check runs

    Your code runs first, then each of these lines. The output must match exactly.

    RunsExpected output
    print(get_grade(95))A
    print(get_grade(83))B
    print(get_grade(72))C

    More Function exercises

    All Python exercises · 50 practice problems · Functions quiz