# Python program to calculate student grade

Here, we are implementing a python program that will input student details, marks in 5 subjects and calculating the student grade.
Submitted by Pankaj Singh, on June 25, 2019

Given students details, marks in 5 subjects and we have to find student's grade.

In this program, we are taking student name, roll number and marks in 5 subjects and calculating student's grade based on the percentage and printing the all details.

## Python code to find student grade

```# Python code to find student grade

class Student:
def __init__(self):
self.__roll=0
self.__name=""
self.__marks=[]
self.__total=0
self.__per=0
self.__result=""

def setStudent(self):
self.__roll=int(input("Enter Roll: "))
self.__name=input("Enter Name: ")
print("Enter marks of 5 subjects: ")
for i in range(5):
self.__marks.append(int(input("Subject "+str(i+1)+": ")))

def calculateTotal(self):
for x in self.__marks:
self.__total+=x

def calculatePercentage(self):
self.__per=self.__total/5

if self.__per>=85:
elif self.__per>=75:
elif self.__per>=65:
elif self.__per>=55:
elif self.__per>=50:
else:

def calculateResult(self):
count=0
for x in self.__marks:
if x>=50:
count+=1
if count==5:
self.__result="PASS"
elif count>=3:
self.__result="COMP."
else:
self.__result="FAIL"

def showStudent(self):
self.calculateTotal()
self.calculatePercentage()
self.calculateResult()

def main():
#Student object
s=Student()
s.setStudent()
s.showStudent()

if __name__=="__main__":
main()
```

Output

```Enter Roll: 101
Enter Name: Prem Sharma
Enter marks of 5 subjects:
Subject 1: 22
Subject 2: 33
Subject 3: 55
Subject 4: 66
Subject 5: 77
101              Prem Sharma             253             50.6            D
COMP.
```

TOP Interview Coding Problems/Challenges

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates