easy +8 pts

Grade Calculator

Convert numeric scores to letter grades with a clear boundary rule.

Write a function named `grade_calculator(score)` that accepts a single numeric argument `score` (int or float) and returns the corresponding letter grade as a string. The grading scale is as follows: 90-100 → 'A', 80-89 → 'B', 70-79 → 'C', 60-69 → 'D', 0-59 → 'F'. If the score is outside the range 0 to 100 inclusive, the function should raise a `ValueError` with the message "Score must be between 0 and 100.". When the score is exactly on a boundary (e.g., 90), it belongs to the higher grade (i.e., 90 is 'A'). Ensure the function handles integer and floating-point scores correctly. For scores that trigger a ValueError, the test harness expects the exception to be raised; the grader will catch it automatically.

Constraints

Input `score` is an int or float. The function must raise `ValueError` for scores outside [0, 100].

Example

>>> grade_calculator(95)
'A'
>>> grade_calculator(89.9)
'B'
>>> grade_calculator(59)
'F'
>>> grade_calculator(100)
'A'
8 points ~10 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Use if-elif checks starting from the highest grade.
Remember to validate the range before or within the checks.
Boundary scores like 90, 80, etc., should go to the higher grade.
Use `raise ValueError("Score must be between 0 and 100.")` for invalid input.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.