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 »





Comments and Discussions




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

© https://www.includehelp.com some rights reserved.