Construct a class named student consisting of a student identification number, list of five grades, and an integer representing the total value of grades entered. The constructor for this class should initialize all student data members to zero. Included in the class the functions/ methods for:
1. Constructor and a Destructor.
2. Create an assessor method to enter a student number
3. Create a method to enter a single test grade (used loop for entering 5 grades)
4. Create a mutator method – to computer an average grade
5. Create a method to display the student number and average grade.
class Student:
# Initializing
def __init__(self):
self.studentIdentificationNumber = ""
self.listFiveGrades =[]
self.totalValueGradesEntered = 0
# Deleting (Calling destructor)
def __del__(self):
print('Destructor called, Student deleted.')
def inputStudentNumber(self):
self.studentIdentificationNumber = input("Enter a student number: ")
def inputGrades(self):
for i in range(1,6):
grade=int(input(f"Enter grade {i}: "))
self.listFiveGrades.append(grade)
self.totalValueGradesEntered+=grade
def calculateAverageGrade(self):
return self.totalValueGradesEntered/5.0
def display(self):
print(f"The student number: {self.studentIdentificationNumber}")
print(f"The student average grade: {self.calculateAverageGrade()}")
obj = Student()
obj.inputStudentNumber()
obj.inputGrades()
obj.display()
del obj
Comments
Leave a comment