Answer: Find the average of the three marks, then check it against the grade limits from the top down using >=.
m1 = float(input("Enter marks in subject 1: "))
m2 = float(input("Enter marks in subject 2: "))
m3 = float(input("Enter marks in subject 3: "))
avg = (m1 + m2 + m3) / 3
if avg >= 90:
grade = "A"
elif avg >= 80:
grade = "B"
elif avg >= 70:
grade = "C"
elif avg >= 60:
grade = "D"
else:
grade = "F"
print("Average =", round(avg, 2))
print("Grade =", grade)
How it works
- The average is \((m_1+m_2+m_3)/3\).
- The
if–elif chain is checked from the highest grade down. Each test uses >=, so the boundary marks 90, 80, 70 and 60 get grades A, B, C and D, and decimal averages such as 89.67 still get a grade (B).
- Anything below 60 falls to
else and gets F.
Sample: marks 90, 90, 90 → average 90.0, grade A; marks 80, 79, 80 → average 79.67, grade C.
The earlier answer's tests (90 < ptg <= 100, 80 < ptg <= 89 and so on) print no grade at all for averages of exactly 90, 80, 70, 60 or 0, or for decimals such as 89.5.