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
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}")
Corresponding letter grade: B
- 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