# Python Program to Calculate Total Marks Percentage and Grade of a Student

In this article, you will learn how to find the **Total**, **Average**, **Percentage**, and **Grade** of a student in the Python language.

### Example

**Enter the marks of five subjects::
98
92
87
82
75**

**The Total marks is: 434.0 / 500.00**

**The Average marks is: 86.8**

**The Percentage is: 86.8 %**

**The Grade is: B**

You should have the knowledge of the following topics in python programming to understand this program:

- Objective Python
- Python Functions
- Python
**If**statement - Python
**input()**function - Python
**print()**function

### Standard Formula

**Total = marks1 + marks2 + marks3 + marks4 + marks5**

**Average = Total / 5.0**

**Percentage = (Total / 500.0) x 100**

Where `marks1`

, `marks2`

, `marks3`

, `marks4`

, and `marks5`

are the marks of five subjects.

In this article, we solve this problem in four methods:

## Python Program to Calculate Total Marks Percentage and Grade of a Student

- Create the
**5**input variables named

to take input marks of the 5 subjects.**subject_1, subject_2, subject_3, subject_4, subject_5** - Then make sum of these marks and assigned it to the

variable.**total** - To calculate the average total value divided by
**5**. - To calculate the percentage total multiplied by
**500**and divided by**5**. - After calculating the average compare the average value with some values to find the grade:
- If

then**average >= 90****Grade -**`A`

- If

then**average >= 80 and average < 90****Grade -**`B`

- If

then**average >= 70 and average < 80****Grade -**`C`

- If

then**average >= 60 and average < 70****Grade -**`D`

- If

then**average < 60****Grade -**`E`

- If

```
# Python Program to Calculate Total Marks Percentage and Grade of a Student
print("Enter the marks of five subjects::")
subject_1 = float (input ())
subject_2 = float (input ())
subject_3 = float (input ())
subject_4 = float (input ())
subject_5 = float (input ())
total, average, percentage, grade = None, None, None, None
# It will calculate the Total, Average and Percentage
total = subject_1 + subject_2 + subject_3 + subject_4 + subject_5
average = total / 5.0
percentage = (total / 500.0) * 100
if average >= 90:
grade = 'A'
elif average >= 80 and average < 90:
grade = 'B'
elif average >= 70 and average < 80:
grade = 'C'
elif average >= 60 and average < 70:
grade = 'D'
else:
grade = 'E'
# It will produce the final output
print ("\nThe Total marks is: \t", total, "/ 500.00")
print ("\nThe Average marks is: \t", average)
print ("\nThe Percentage is: \t", percentage, "%")
print ("\nThe Grade is: \t", grade)
```

### Output

`Enter the marks of five subjects::`

98

92

87

82

75

`The Total marks is: 434.0 / 500.00`

`The Average marks is: 86.8`

`The Percentage is: 86.8 %`

`The Grade is: B`

### Explanation

` Average:` we take the marks of five subjects as input after that the sum of these marks is divided by

**5**then It will return the average value of the marks.

` Percentage:` we made a division of the sum of the user's marks by

**500**and then multiplied by

**100**then It will return the percentage value of the marks.

` Grade:` we compared the value of the Average marks with this range of marks to find the Grade of students like:

If `Average marks >= 90`

then Its Grade is **'A'**

If `Average marks >= 80 and < 90`

then Its Grade is **'B'**

If `Average marks >= 70 and < 80`

then Its Grade is **'C'**

If `Average marks >= 60 and < 70`

then Its Grade is **'D'**

If `Average marks < 60`

then Its Grade is **'E'**

## Python Program to Find Grade and Average Marks of a Student Using Function

- There is used same calculation as used above on the program.
- In this program, we created a function named

with**CalcPercentGrade()****5**arguments in marks of the students. - After the same calculation process, It will print the final output of the program like Total marks, Average, Percentage, and Grade of the student.

```
# Python Program to Find Grade and Average Marks of a Student Using Function
# Custom function to Display Percentage & Grade
def CalcPercentGrade (S_1, S_2, S_3, S_4, S_5):
# It will calculate the Total, Average and Percentage
total = S_1 + S_2 + S_3 + S_4 + S_5
average = total / 5.0
percentage = (total / 500.0) * 100
if average >= 90:
grade = 'A'
elif average >= 80 and average < 90:
grade = 'B'
elif average >= 70 and average < 80:
grade = 'C'
elif average >= 60 and average < 70:
grade = 'D'
else:
grade = 'E'
# It will produce the final output
print ("\nThe Total marks is: \t", total, "/ 500.00")
print ("\nThe Average marks is: \t", average)
print ("\nThe Percentage is: \t", percentage, "%")
print ("\nThe Grade is: \t", grade)
# Driver function to Run this Program
print("Enter the marks of five subjects::")
subject_1 = float (input ())
subject_2 = float (input ())
subject_3 = float (input ())
subject_4 = float (input ())
subject_5 = float (input ())
total, average, percentage, grade = None, None, None, None
# It will produce the final output
CalcPercentGrade (subject_1, subject_2, subject_3, subject_4, subject_5)
```

### Output

`Enter the marks of five subjects::`

97

96

92

88

85

`The Total marks is: 458.0 / 500.00`

`The Average marks is: 91.6`

`The Percentage is: 91.60000000000001 %`

`The Grade is: A`

#### Also, visit these links

__Python Program to Perform Arithmetic Operations__

__Find the Area of Rectangle in Python__

## Python Program to Calculate Total Marks Percentage and Grade of a Student using Nested If else

- In this program, we applied nested
**if-else statements**to make comparisons of student marks and find the grade of students. - Then It will be returned the final output of the program same as the above program.

```
# Python Program to Calculate Total Marks Percentage and Grade of a Student using Nested If else
print("Enter the marks of five subjects::")
subject_1 = float (input ())
subject_2 = float (input ())
subject_3 = float (input ())
subject_4 = float (input ())
subject_5 = float (input ())
total, average, percentage, grade = None, None, None, None
# It will calculate the Total, Average and Percentage
total = subject_1 + subject_2 + subject_3 + subject_4 + subject_5
average = total / 5.0
percentage = (total / 500.0) * 100
if average >= 90:
grade = 'A'
else:
if average >= 80 and average < 90:
grade = 'B'
else:
if average >= 70 and average < 80:
grade = 'C'
else:
if average >= 60 and average < 70:
grade = 'D'
else:
grade = 'E'
# It will produce the final output
print ("\nThe Total marks is: \t", total, "/ 500.00")
print ("\nThe Average marks is: \t", average)
print ("\nThe Percentage is: \t", percentage, "%")
print ("\nThe Grade is: \t", grade)
```

## Python Program to Calculate Total Marks Percentage and Grade of a Student Using Class

- To make this program we created a class named StudentData, and its properties like

.**Total, Average, Percentage, Marks, and MaxMarks** - After that created some methods:

,**CalcMaxMarks()**

,**CalcTotal()**

,**CalcAvg()**

,**CalcPercentage()**

, and**CalcGrade()**

.**CalcResult()** - These created methods will return the desired outputs.

```
# Python Program to Calculate Total Marks Percentage and Grade of a Student Using Class
class StudentData:
def __init__(self):
self.Total = 0.00
self.Average = 0.00
self.Percentage = 0.00
self.Marks = []
self.MaxMarks = 0.00
def main(self):
print("Enter the marks of five subjects::")
for i in range(5):
self.Marks.append( float (input ()))
def CalcMaxMarks (self):
return len (self.Marks) * 100
def CalcTotal (self):
self.Total = 0
for i in self.Marks:
self.Total += i
return self.Total
def CalcAvg (self):
self.Average = self.Total / len (self.Marks)
return self.Average
def CalcPercentage (self):
return (self.Total * 100) / (len (self.Marks) * 100)
def CalcGrade (self):
Grade = None
if self.Average >= 90:
Grade = 'A'
elif self.Average >= 80 and self.Average < 90:
Grade = 'B'
elif self.Average >= 70 and self.Average < 80:
Grade = 'C'
elif self.Average >= 60 and self.Average < 70:
Grade = 'D'
else:
Grade = 'E'
return Grade
def CalcResult (self):
c = 0
for i in self.Marks:
if i >= 40:
c += 1
if c == len (self.Marks):
return 'Passed'
else:
return 'Failed'
# It will create instance of the StudentData class
StudentData = StudentData()
StudentData.main()
# It will produce the final output
print ("\nThe Total marks is: \t", StudentData.CalcTotal(), "/", StudentData.CalcMaxMarks())
print ("\nThe Average marks is: \t", StudentData.CalcAvg())
print ("\nThe Percentage is: \t", StudentData.CalcPercentage(), "%")
print ("\nThe Grade is: \t", StudentData.CalcGrade())
print ("\nThe Result is: \t", StudentData.CalcResult())
```

### Output

`Enter the marks of five subjects::`

80

70

75

65

60

`The Total marks is: 350.0 / 500`

`The Average marks is: 70.0`

`The Percentage is: 70.0 %`

`The Grade is: C`

`The Result is: Passed`

**Note:**If the marks in each subject are**greater than or equal to 40**then Student will be passed otherwise It will fail.### Explanation

In the above program, we have taken some **objects** & **methods** to calculate and store the output values, It will be returned at end of the program:

#### Used Objects in the Program:

**Total**- To store the sum of total marks**Average**- To store an average of marks**Percentage**- To sore the percentage value of marks**Marks**- To store the marks of the given subject**MaxMarks**- To calculate maximum marks

#### Used Methods in the Program:

**main()**- it's a driver method**CalcMaxMarks()**- it will calculate maximum marks**CalcTotal()**- It will calculate the total marks**CalcAvg()**- It will calculate the average of the marks**CalcPercentage()**- It will calculate the percentage of the total marks**CalcGrade()**- It will calculate the Grade of the student as per marks**CalcResult()**- It will define student passed or failed on behalf of their own marks