Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Classify Exam Grade

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

Python practice15 minControl Flow (If–Else Logic)IntermediateLast updated March 15, 2026

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

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 1

Input

89.5

Output

B

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