Python Practice › OOP Programs › Program 35

StudentRecord with average grade

EasyOOP Programs · 35 of 48

Create StudentRecord with name, age and grades, with methods for the average and a summary.

Advertisement
Output
Meena, 16, average 86.33

Approach

  1. sum(grades) / len(grades).

Solution

Python
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.

More oop programs

← All 48 OOP Programs

Leave a Comment