Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Problem No 14

Classify Exam Grade

Medium

15 minute session

Summary

Convert a numerical exam score into a letter grade using conditional branching.

Problem statement

Write a function classify_grade(score) that takes a numeric score (int or float) and returns a letter grade according to the scale: - 90 to 100 -> 'A' - 80 to 89.999... -> 'B' - 70 to 79.999... -> 'C' - 60 to 69.999... -> 'D' - 0 to 59.999... -> 'F' If the score is outside the range 0 to 100, return the string 'Invalid score'. Use precise boundary handling so that 90.0 yields 'A', 89.999 yields 'B', etc.

Task

Implement grade classification using if/elif/else and handle invalid scores.

Examples

High score

Input

95

Output

A

Explanation

95 lies between 90 and 100 inclusive, so the grade is 'A'.

Input format

A single number (int or float) representing the score.

Output format

Return a string: one of 'A', 'B', 'C', 'D', 'F', or 'Invalid score'.

Constraints

Scores may be floats. Treat 0 <= score <= 100 as valid; everything else is invalid.

Samples

Sample input 0

89.5

Sample output 0

B

Explanation 0

89.5 is >=80 and <90, so it's a 'B'.

Code editor
Loading editor…

AI assistant

Ask me anything!

Need help? I can explain the core idea behind this problem, review your current code, and give targeted hints. Use “Teach Theory” for the concept, “Get AI hint” for a quick scaffold nudge, or ask a specific question below.

Chat history is temporary and will not be saved.

03:52 AM

Free preview includes 1 Teach Theory response and 1 AI hint per unlocked preview lesson.