Python Program to Calculate Grade of Student

« Previous Program Next Program »

Calculate Grade of Student in Python

To calculate grade of students in python, you have to ask from user to enter marks obtained in 5 subjects and calculate the sum of all the marks and then calculate the average marks to find the grade according to the average marks obtained by student as shown in the program given below.

Python Programming Code to Calculate Grade of Student

Following python program ask from user to enter marks obtained in 5 subjects to calculate the grade of student:

# Python Program - Calculate Grade of Student

print("Enter 'x' for exit.");
print("Enter marks obtained in 5 subjects: ");
mark1 = input();
if mark1 == 'x':
    mark1 = int(mark1);
    mark2 = int(input());
    mark3 = int(input());
    mark4 = int(input());
    mark5 = int(input());
    sum = mark1 + mark2 + mark3 + mark4 + mark5;
    average = sum/5;
    if(average>=91 and average<=100):
    	print("Your Grade is A+");
    elif(average>=81 and average<=90):
    	print("Your Grade is A");
    elif(average>=71 and average<=80):
    	print("Your Grade is B+");
    elif(average>=61 and average<=70):
    	print("Your Grade is B");
    elif(average>=51 and average<=60):
    	print("Your Grade is C+");
    elif(average>=41 and average<=50):
    	print("Your Grade is C");
    elif(average>=0 and average<=40):
    	print("Your Grade is F");
    	print("Strange Grade..!!");

Here are some sample runs of the above python program to demonstrate how to calculate the grade of student.

When you run the above code, you will see the following sample output asking from the user to enter his/her marks obtained in his/her 5 subjects:

calculate student grade python

Now enter marks obtained in 5 subjects and then press enter key to see the grade obtained according to your marks:

calculate grade of student python

Here is the same program with run on python shell. This is the first snapshot:

python calculate grade of student

This is the second snapshot:

calculate student grade in python

Here is the third snapshot:

find student grade in python

Same Program in Other Languages

You may also like to learn or practice the same program in other popular programming languages:

« Previous Program Next Program »


Quick Links
Signup - Login - Give Online Test