Home »
Python »
Python programs
Python program to search student record using percentage
Here, we are going to learn how to search student record using percentage in Python?
Submitted by Shivang Yadav, on February 18, 2021
Problem Statement: Here, we will see a program to search for a student's record based on his/her percentage.
Problem Solution: We have the student's record consisting of marks in three subjects, we will calculate his/her percentage and then search from specific records using the percentage value.
Class and its member used:
- Class : Student
- Method : GetStudent() - gets student's information from the user and calculates result using result() method.
- Method : putStudent() - prints student's result.
- Method : result() - calculate the result i.e. percentage and result (pass or fail).
- Method : Search() - check weather the student's information is within the given range (min - max).
Program to search students record using percentage
class Student:
def getStudent(self):
self.__rollno = input("Enter Roll No: ")
self.__name = input("Enter Name: ")
self.__phy = int(input("Enter Physics Marks: "))
self.__chem = int(input("Enter Chemistry Marks: "))
self.__math = int(input("Enter Maths Marks: "))
self.result()
def putStudent(self):
print("Roll Number: ", self.__rollno, end = " ")
print("Name: ", self.__name, end = " ")
print("Percentage: ", self.__percentage, end = " ")
if (self.__percentage >= 60):
print("Pass")
else:
print("Fail")
def result(self):
total = self.__phy + self.__chem + self.__math
self.__percentage = (int)(total / 3)
def search(self,min,max):
if(self.__percentage>=min and self.__percentage<=max):
return True
else:
return False
studentList = list()
while(True):
studentObject=Student()
studentObject.getStudent()
studentList.append(studentObject)
ch=input("Continue y/n? ")
if ch == 'n':
break
min=int(input("Enter Min Percentage: "))
max=int(input("Enter Max Percentage: "))
searchList = list()
for studentObject in studentList:
found=studentObject.search(min,max)
if(found):
searchList.append(studentObject)
if(len(searchList)==0):
print('No Record Exist')
else:
for studentObject in searchList:
studentObject.putStudent()
Output:
Enter Roll No: 54
Enter Name: John
Enter Physics Marks: 34
Enter Chemistry Marks: 54
Enter Maths Marks: 23
Continue y/n? y
Enter Roll No: 02
Enter Name: Jane
Enter Physics Marks: 89
Enter Chemistry Marks: 76
Enter Maths Marks: 69
Continue y/n? n
Enter Min Percentage: 50
Enter Max Percentage: 99
Roll Number: 02 Name: Jane Percentage: 78 Pass
Python class & object programs »