Python Practice › OOP Programs › Program 35
StudentRecord with average grade
Create StudentRecord with name, age and grades, with methods for the average and a summary.
Output
Meena, 16, average 86.33
Approach
sum(grades) / len(grades).
Solution
class StudentRecord: def __init__(self, name, age, grades): self.name, self.age, self.grades = name, age, grades def average(self): return round(sum(self.grades) / len(self.grades), 2) def show(self): print(f"{self.name}, {self.age}, average {self.average()}") StudentRecord("Meena", 16, [88, 92, 79]).show()Output
Meena, 16, average 86.33
Learn the concept
New to this topic? Read the lesson, then come back.