Write a program to find the grade of a student when grades are allocated as given in the table below.
| Percentage of Marks | Grade |
|---|---|
| Above 90% | A |
| 80% to 90% | B |
| 70% to 80% | C |
| 60% to 70% | D |
| Below 60% | E |
Percentage of the marks obtained by the student is input to the program.
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →Consecutive percentage slabs map naturally onto an if–elif–else ladder — test from the top slab downwards, so each elif only needs the slab's LOWER bound.
The idea. The grade table is a set of contiguous ranges, and the clean way to code ranges is an if–elif ladder ordered from highest to lowest: once "per > 90" has failed, we already know per <= 90, so the next test needs only the lower bound (per >= 80), and so on. The final else catches "below 60%" with no test at all.
One boundary decision must be made explicit, because the printed table lists 80% and 70% etc. in two rows each ("80% to 90%" and "70% to 80%"): reading "Above 90%" strictly, 90 itself is a B; and taking each slab as inclusive of its lower bound, 80 → B, 70 → C, 60 → D. The ladder below implements exactly that.
Program
per = float(input("Enter percentage of marks: "))
if per > 90:
grade = "A"
elif per >= 80:
grade = "B"
elif per >= 70:
grade = "C"
elif per >= 60:
grade = "D"
else:
grade = "E"
print("Grade:", grade)
Sample runs
Enter percentage of marks: 85
Grade: B
Enter percentage of marks: 58.5
Grade: E
Boundary check
| Input | First true test | Grade |
| --- | --- | --- | …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.