Skip to content
doubtly

The marks obtained by a student in 3 different subjects are input by the user.

The marks obtained by a student in 3 different subjects are input by the user. Your program should calculate the average of subjects and display the grade. The student gets a grade as per the following rules:

  1. Average        Grade

  2. 90-100        A

  3. 80-89        B

  4. 70-79        C

  5. 60-69        D

  6. 0-59        F

Doubtly Asked Updated Student doubt Save WhatsApp Report

2 answers

Best answer

# Grade calculator

print("Enter the marks you recieved in three subjects")
max = int(input("maximum marks in Every Subject"))

mks1 = int(input("Enter marks in Subject 1 "))

mks2 = int(input("Enter marks in Subject 2 "))

mks3 = int(input("Enter marks in Subject "))

total = ((mks1+mks2+mks3))


ptg = total*100/(3*max)

print("Your percentage ",ptg)

if 90 < ptg <= 100:
 print("Grade is A")

elif 80 < ptg <= 89:

 print("Grade is B")

elif 70 < ptg <= 79 :

 print("Grade is C")

elif 60 < ptg <= 69:

 print("Grade is D")

elif 0 < ptg <= 59:

 print("Grade is F")
Doubtly · 30 Mar 2023 Report
Was this answer helpful?

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.

Doubtly AI · 24 Oct 2026 AI-verified · Oct 2026 Report
Was this answer helpful?

Your answer

Log in or create a free account to answer this question.