In this python if else program, we will assign grades to each student as per total marks scored.
Condition for grades:
Marks less than 40: Fail
Marks between 40-50: Grade C
Marks between 51-60: Grade B
Marks between 61-70: Grade A
Marks between 71-80: Grade A+
Marks between 81-90: Grade A++
Marks between 91-100: Excellent
Hint:
Use Multiple if-else statements.
Steps to solve the program
- Take marks as input through the user.
- Using if-else statements assign grades as per the total marks given.
- Use the grades given in the question.
- Print the output.
# Take marks through the user
marks = int(input("Enter marks: "))
# Assign grades based on marks
if marks<40:
# marks is less than 40 then print Fail
print("Fail")
elif marks>=40 and marks>=50:
# marks is greater than 40 and less than 50 then got C grade.
print("Grade C")
elif marks>50 and marks<=60:
# marks is greater than 50 and less than 60 then got B grade.
print("Grade B")
elif marks>60 and marks<=70:
# marks is greater than 60 and less than 70 then got A grade.
print("Grade A")
elif marks>70 and marks<=80:
# marks is greater than 70 and less than 80 then got A+ grade.
print("Grade A+")
elif marks>80 and marks<=90:
# marks is greater than 80 and less than 90 then got A++ grade.
print("Grade A++")
elif marks>90 and marks<=100:
# marks is greater than 90 and less than 100 then got Excellent grade.
print("Excellent")
else:
# marks is greater than 100 than consider as invalid number..
print("Invalid marks")
Output :
Enter marks: 62
Grade C
Enter marks: 30
Fail
Enter marks: 93
Excellent
Enter marks: 100
Invalid marks
Related Articles
- Python program to check the given number divided by 3 and 5.
- Python program to print the square of the number if it is divided by 11.
- Python program to check given number is a prime number or not.
- Python program to check given number is odd or even.
- Python program to check a given number is part of the Fibonacci series from 1 to 10.
- Python program to check authentication with the given username and password.