Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialjoshua korir
1,445 Pointswhat is wrong with my code
inheritance
class Inventory:
def __init__(self):
self.slots = []
def add_item(self, item):
self.slots.append(item)
class SortedInventory(Inventory):
def __init__(self):
super().__init__()
4 Answers
Chris Freeman
Treehouse Moderator 68,441 PointsYou are close. You’ve overridden the __init__
method not the add_item
method.
Edit: You can override add_item
the same way __init__
was over ridden. Just change the names and be sure to include the item
parameter. The first task you’re creating a redundant method to the parent’s method. It’s a needed set up for Task 2.
Edit 2:
- literally replace
__init__
withadd_item
, in your original code. - add
item
parameter to both the method definition and as an argument to the super call:super().add_item(item)
Post back if you need more help. Good luck!!!
joshua korir
1,445 Pointshow is that done? i thought the subclass automatically enables us to access all method s of it parents
Chris Freeman
Treehouse Moderator 68,441 PointsSee updated answer
joshua korir
1,445 Pointsim still stuck
Chris Freeman
Treehouse Moderator 68,441 PointsSee Edit 2 above
joshua korir
1,445 Pointsi dont think the video covered this
Chris Freeman
Treehouse Moderator 68,441 PointsIt didn't cover this exact scenario. It requires you to apply the concepts to a slight newer tasks. All of the concepts have been shown, just not this exact task.