Grade Calculator
Turn marks into letter grades with an ordered Python if-elif chain. Students examine cutoff scores, decimal marks, and why range validation is a separate step.
1# Take marks as input2marks = float(input("Enter marks (0-100): "))34# Assign grade based on marks5if marks >= 90:6 print("Grade: A")7elif marks >= 80:8 print("Grade: B")9elif marks >= 70:10 print("Grade: C")11elif marks >= 60:12 print("Grade: D")13else:14 print("Grade: F")
Output
Enter marks (0-100): 85 Grade: B Enter marks (0-100): 45 Grade: F
In this one
- Build descending grade bands
- Include exact cutoffs
- Separate prompts from validation
How it works
- 1
Read marks as a float.
- 2
Try cutoffs ninety, eighty, seventy, then sixty.
- 3
Print the first grade matched or F.
Edge cases
What grade does 90 receive?
What grade does 90 receive?
A, because the first comparison includes equality.
Does 105 get rejected?
Does 105 get rejected?
No. It prints A; a real marks form should validate the range first.
What's going on
Grade bands are checked from the highest cutoff downward. marks is a float, so a score such as 89.5 can be compared without discarding its fractional part.
A score of 85 fails the ninety test but passes the eighty test, giving B. Later tests do not run. A score below sixty reaches F. The prompt says zero to one hundred, but this example does not enforce that range.
What grade does 90 receive? A, because the first comparison includes equality.
Does 105 get rejected? No. It prints A; a real marks form should validate the range first.
Quiz
Tap an option. The answer stays hidden until you pick.
Question 1
Why start with the highest cutoff?
Pick an answer to check it.
Question 2
What grade does 90 receive?
Pick an answer to check it.
Questions people ask
What grade does 90 receive?
A, because the first comparison includes equality.
Does 105 get rejected?
No. It prints A; a real marks form should validate the range first.
Why start with the highest cutoff?
A high mark also exceeds lower cutoffs.
๐Related Content
- ๐
Phase 1 - Learn Concepts
Review Phase 1 concepts and explanations
- ๐
Phase 1 - Quiz
Test your Phase 1 understanding with quiz questions
- ๐ป
Phase 1 - All Practice Problems
Explore all practice problems for Phase 1
- ๐
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- ๐ง
Logic Building Overview
Learn about the complete logic building curriculum