Part of the series

Several example codes

~2 min read • Updated Oct 11, 2025

Program Overview

This Python program reads a numeric score between 0 and 100 and returns the corresponding letter grade.
The grading rules are as follows:
- If the score is between 80 and 100, it returns A
- If the score is between 60 and 80, it returns B
- If the score is between 50 and 60, it returns C
- If the score is less than 50, it returns F


Python Code:


def grade_letter(score: float) -> str:
    if 80 <= score <= 100:
        return "A"
    elif 60 <= score < 80:
        return "B"
    elif 50 <= score < 60:
        return "C"
    elif 0 <= score < 50:
        return "F"
    else:
        return "Invalid score"

# Read score from user
score = float(input("Enter a score between 0 and 100: "))
letter = grade_letter(score)
print(f"Corresponding letter grade: {letter}")

Sample Output (input: 75):


Corresponding letter grade: B

Step-by-Step Explanation:

- The user enters a numeric score
- The program checks which range the score falls into
- Based on the range, it returns the appropriate letter grade
- If the score is outside the valid range, it returns an error message


Written & researched by Dr. Shahin Siami