Fix the Student Class
Intermediate · Fix the bug · from Python Classes and Objects: OOP from the Ground Up
From the lesson: Python Classes and Objects: OOP from the Ground Up
Imagine you own a bakery and you have a cookie cutter shaped like a star. Every time you press it into dough, you get a new star-shaped cookie. The cutter itself isn't a cookie - it's a blueprint for making cookies.
Read the lessonThis Student class has two bugs. Fix them so the code prints:
Alice: 85.0class Student:
def __init__(self, name):
self.name = name
grades = []
def add_grade(self, grade):
self.grades.append(grade)
def average(self):
return sum(self.grades) / len(self.grades)
s = Student('Alice')
s.add_grade(90)
s.add_grade(80)
print(f'{s.name}: {s.average()}')
More Classes and Objects exercises
- Create a Book ClassBeginner
- Add a Method to RectangleBeginner
- Predict the Counter OutputBeginner
- Add __str__ to a ProductIntermediate
- Build a Player Class with Score TrackingIntermediate
- Refactor Functions into a ClassAdvanced
All Python exercises · 50 practice problems · Object-Oriented Programming quiz