Write Python code to define a class called Student.
The Student class should have the following private fields:
The Student class should have the following methods:
In the same file, write a main function to test the functionality of the Student class.
class Student: def __init__(self, name='', attend=0, grades=[]): self.name = name self.attend = attend self.grades = grades def get_name(self): return self.name def attendClass(self): self.attend += 1 def addGrade(self, grade): self.grades.append(grade) def __str__(self): result = 'Name: ' + self.name + '\n' result += 'Number of classes attending: ' + str(self.attend) + '\n' result += 'Grades are: ' + str(self.grades) return result def main(): s = Student('Ronaldo') s.attendClass() s.addGrade(97) s.attendClass() s.addGrade(92) print(s) main()
Get Answers For Free
Most questions answered within 1 hours.