- 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
- Give Online Test
- All Test List
- Python Online Test

In this article, you will learn and get code in python to calculate grade of students. Here are the list of programs on finding grade of students:

- Calculate Grade of Student based on Marks obtained in 5 Subjects
- based on Marks obtained in
**n**number of Subjects

The grade must be calculated as per 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 |

This program find and prints grade of student based on marks obtained in 5 subjects entered by user at run-time.

To calculate grade of students in python, you have to ask from user to enter marks obtained in 5 subjects. Now 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:

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

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 asking from the user to enter marks obtained in 5 subjects:

Now enter marks obtained in 5 subjects say **89, 99, 98, 92, 77** and then press `ENTER`

key to see
the grade obtained according to 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 with floating-point (value 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())

This program uses *for loop* to receive marks obtained in 5 subjects. It also uses *for 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, 35** as marks obtained in 5 subjects:

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

mark.insert(i, input())

with the statement given below:

mark.append(input())

The following block of code (from 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 statements gets executed five times with the value of **i** from 0 to 4.

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

This program allows user to enter the number of subjects along with marks obtained in all subjects. That is, this
program find and prints grade of student based on marks obtained in **N** subjects. The value of **N** and
marks in **N** subjects must be entered by 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 number of subjects and **56, 46, 76, 87, 45, 37** as marks obtained in 6 subjects:

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

« Previous Program Next Program »

© Copyright 2021. All Rights Reserved.