- Python Basic Programs
- Python Program Examples
- Python Print Hello World
- Python Get Input from User
- Python Add Two Numbers
- Add Subtract Multiply Divide
- Python Check Even or Odd
- Python Check Prime or Not
- Python Check Alphabet or Not
- Python Check Vowel or Not
- Python Check Leap Year or Not
- Check Reverse equal Original
- Check Positive Negative Zero
- Python Check Armstrong or Not
- Python Check Palindrome or Not
- Python Check Perfect Number
- Python Find Reverse of Number
- Python Count Digits in Number
- Python Add Digits of Number
- Sum of First and Last Digits
- Python Product of Mid Digits
- Sum of Squares of Digits
- Interchange Digits of Number
- Python Sum of n Numbers
- Python Print ASCII Values
- Python Swap Two Numbers
- Python Swap Two Variables
- Python Fahrenheit to Celsius
- Python Celsius to Fahrenheit
- Python Display Calendar
- Python Days into Years, Weeks
- Find Largest of Two Number
- Find Largest of Three Number
- Python Print Fibonacci Series
- Generate Armstrong Numbers
- Python Make Simple Calculator
- Python Add Binary Numbers
- Binary Number Multiplication
- Python Mathematical Programs
- Find Sum of Natural Numbers
- Find Average of n Numbers
- Python Print Multiplication Table
- Print Table using Recursion
- Python Find Average Percentage
- Python Find Grade of Student
- Find Square Root of Number
- Python Print Prime Numbers
- Find Numbers Divisible by
- Python Find Factors of Number
- Python Find Factorial of a Number
- Python Find HCF & LCM
- Python Kilometres to Miles
- Python Find Area of Square
- Python Find Area of Rectangle
- Python Find Area of Triangle
- Python Find Area of Circle
- Python Find Perimeter of Square
- Find Perimeter of Rectangle
- Python Find Perimeter of Triangle
- Find Circumference of Circle
- Python Simple Interest
- Python Solve Quadratic Equation
- Python Different Set of Operations
- Python Display Powers of 2
- Python Find nCr & nPr
- Python Pattern Programs
- Python Print Pattern Programs
- Python Print Diamond Pattern
- Python Print Floyd's Triangle
- Python Print Pascal's Triangle
- Python List Programs
- Python Count Even/Odd in List
- Python Positive/Negative in List
- Python Even Numbers in List
- Python Odd Numbers in List
- Python Sum of Elements in List
- Sum of Odd/Even Numbers
- Python Element at Even Position
- Python Element at Odd Position
- Python Search Element in List
- Python Largest Number in List
- Python Smallest Number in List
- Python Second Largest in List
- Python Second Smallest in List
- Python Insert Element in List
- Python Delete Element from List
- Python Multiply Numbers in List
- Swap Two Elements in List
- Python 1D Array Program
- Python Linear Search
- Python Binary Search
- Python Insertion Sort
- Python Bubble Sort
- Python Selection Sort
- Remove Duplicates from List
- Python Reverse a List
- Python Merge Two List
- Python Copy a List
- Python Conversion Programs
- Python Decimal to Binary
- Python Decimal to Octal
- Python Decimal to Hexadecimal
- Python Binary to Decimal
- Python Binary to Octal
- Python Binary to Hexadecimal
- Python Octal to Decimal
- Python Octal to Binary
- Python Octal to Hexadecimal
- Python Hexadecimal to Decimal
- Python Hexadecimal to Binary
- Python Hexadecimal to Octal
- Python Matrix Programs
- Python Add Two Matrices
- Python Subtract Two Matrices
- Python Transpose Matrix
- Python Multiply Matrices
- Python String Programs
- Python Print String
- Python Find Length of String
- Python Compare Two Strings
- Python Copy String
- Python Concatenate String
- Python Reverse a String
- Python Swap Two Strings
- Python Uppercase to Lowercase
- Python Lowercase to Uppercase
- Python Check Substring in String
- Python Count Character in String
- Count Repeated Characters
- Python Count Word in Sentence
- Python Count Each Vowels
- Python Capitalize Character
- Python Capitalize Word in String
- Python Smallest/Largest Word
- Remove Spaces from String
- Remove Duplicate Character
- Remove Vowels from String
- Remove Punctuation from String
- Python Remove Word in String
- Python Remove Duplicate Words
- WhiteSpace to Hyphens
- Replace Vowels with Character
- Replace Character in String
- Python Sort String in Alphabetical
- Sort Word in Alphabetical Order
- Extract Number from String
- Python Check Anagram Strings
- Python File Programs
- Python Read a File
- Python Write to File
- Python Append Text to File
- Python Copy Files
- Python Merge Two Files
- Python Counts Characters in File
- Python Count Words in File
- Python File Content in Reverse
- Python Lines Contains String
- Python Delete Line from File
- Python Capitalize Word in File
- Python Replace Text in File
- Replace Specific Line in File
- Python Find Size of File
- Python List Files in Directory
- Python Delete Files
- Python Misc Programs
- Python Reverse a Tuple
- Python Merge Two Dictionary
- Python bytes to String
- Python bytearray to String
- Generate Random Numbers
- Python Print Address of Variable
- Python Print Date and Time
- Python Get IP Address
- Python Shutdown/Restart PC
- Python Tutorial
- Python Tutorial

# Python Program to Calculate a Student's Grade

In this article, you will learn and get code in Python to calculate the grades of students. Here is a list of programs for determining a student's grade:

- Calculate the student's grade based on the results of five subjects.
- Based on the marks obtained in N number of subjects

The grade must be calculated as per the following rules:

Average Mark | Grade |
---|---|

91-100 | A1 |

81-90 | A2 |

71-80 | B1 |

61-70 | B2 |

51-60 | C1 |

41-50 | C2 |

33-40 | D |

21-32 | E1 |

0-20 | E2 |

## Calculate the Grade of the Student in Python

This program figures out and prints a student's grade based on the marks they got in five subjects that the user enters at run time.

To calculate the grade of students in Python, you have to ask the user to enter marks obtained in five subjects. Now, add up all the marks and figure out the average to find the student's grade based on the average marks they got, as shown in the program below:

The following Python program asks the user to enter marks obtained in five subjects to calculate and print the student's grade:

print("Enter Marks Obtained in 5 Subjects: ") markOne = int(input()) markTwo = int(input()) markThree = int(input()) markFour = int(input()) markFive = int(input()) tot = markOne+markTwo+markThree+markFour+markFive avg = tot/5 if avg>=91 and avg<=100: print("Your Grade is A1") elif avg>=81 and avg<91: print("Your Grade is A2") elif avg>=71 and avg<81: print("Your Grade is B1") elif avg>=61 and avg<71: print("Your Grade is B2") elif avg>=51 and avg<61: print("Your Grade is C1") elif avg>=41 and avg<51: print("Your Grade is C2") elif avg>=33 and avg<41: print("Your Grade is D") elif avg>=21 and avg<33: print("Your Grade is E1") elif avg>=0 and avg<21: print("Your Grade is E2") else: print("Invalid Input!")

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

When you run the above code, you will see the following sample output, which asks the user to enter marks obtained in 5 subjects:

Now enter the marks obtained in 5 subjects, say 89, 99, 98, 92, and 77, and then press the ENTER key to see the grade obtained according to the marks entered, as shown in the snapshot given below:

**Note**: If mark contains decimal values like 98.6, 86.9, etc., then replace int with float.

That is, to handle floating-point (values containing decimal) values, replace the following block of code:

markOne = int(input()) markTwo = int(input()) markThree = int(input()) markFour = int(input()) markFive = int(input())

with the block of code given below:

markOne = float(input()) markTwo = float(input()) markThree = float(input()) markFour = float(input()) markFive = float(input())

### Receive marks using Loop and Find Grade

This program uses a loop to receive marks obtained in five subjects. It also uses a loop to find the total mark:

mark = [] tot = 0 print("Enter Marks Obtained in 5 Subjects: ") for i in range(5): mark.insert(i, input()) for i in range(5): tot = tot + int(mark[i]) avg = tot/5 if avg>=91 and avg<=100: print("Your Grade is A1") elif avg>=81 and avg<91: print("Your Grade is A2") elif avg>=71 and avg<81: print("Your Grade is B1") elif avg>=61 and avg<71: print("Your Grade is B2") elif avg>=51 and avg<61: print("Your Grade is C1") elif avg>=41 and avg<51: print("Your Grade is C2") elif avg>=33 and avg<41: print("Your Grade is D") elif avg>=21 and avg<33: print("Your Grade is E1") elif avg>=0 and avg<21: print("Your Grade is E2") else: print("Invalid Input!")

Here is its sample run with user input: 89, 76, 78, 45, and 35 as marks obtained in 5 subjects:

**Note**: You can also use append() in place of insert(). To do so, just replace the following statement:

mark.insert(i, input())

with the statement given below:

mark.append(input())

The following block of code (from the above program):

for i in range(5): mark.insert(i, input())

is created to execute the following statement:

mark.insert(i, input())

five times from 0 to 4. That is, this statement gets executed five times with the value of i ranging from 0 to 4.

When i's value is 0 (at first execution), then the mark entered by the user gets stored in the list at mark[0]. Now, the value of i is 1, so the mark entered by the user is stored in the list at mark[1], and so on up to five times.

### Obtain Marks for N Subjects and Determine Grade

This program allows the user to enter the number of subjects along with the marks obtained in all subjects. That is, this program finds and prints the grade of a student based on the marks obtained in N subjects. The value of N and marks in N subjects must be entered by the user:

mark = [] tot = 0 print("Enter Number of Subjects: ") subNo = int(input()) print("Enter Marks Obtained in " + str(subNo) + " Subjects: ") for i in range(subNo): mark.append(input()) for i in range(subNo): tot = tot + int(mark[i]) avg = tot/subNo if avg>=91 and avg<=100: print("Grade = A1") elif avg>=81 and avg<91: print("Grade = A2") elif avg>=71 and avg<81: print("Grade = B1") elif avg>=61 and avg<71: print("Grade = B2") elif avg>=51 and avg<61: print("Grade = C1") elif avg>=41 and avg<51: print("Grade = C2") elif avg>=33 and avg<41: print("Grade = D") elif avg>=21 and avg<33: print("Grade = E1") elif avg>=0 and avg<21: print("Grade = E2") else: print("Invalid Input!")

Here is its sample run with user input, 6 as the number of subjects, and 56, 46, 76, 87, 45, and 37 as the marks obtained in the 6 subjects:

Here is another sample run with user input, 10 as the total number of subjects, and 56, 76, 87, 90, 45, 44, 34, 56, 76, and 80 as the marks obtained in the 10 subjects:

#### Same Program in Other Languages

« Previous Program Next Program »