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 trialshubhamkt
11,675 PointsSuper Duper
Can't figure out how to access the slots
class Inventory:
slots=[]
def __init__(self):
self.slots = []
def add_item(self, item):
self.slots.append(item)
class SortedInventory(Inventory):
def add_item(self,item):
super().add_item(item)
def __init__(self):
super().__init__()
slots.sort()
3 Answers
Chris Freeman
Treehouse Moderator 68,457 PointsYou are very close. You do not need to override the __init__
method. Task 3 want you to sort the list of items after an item has been added. The addition happens already in the add_item
method. You need only to add the current slots
attribute.
The attribute slots
is inherited from Inventory
so it is available as self.slots
(the same as is done in Inventory
). So a simple self.slots.sort()
should suffice.
Post back if you need more help. Good luck!!
Jeremy Schaar
4,728 PointsHmm. That's what I thought would work, but the following isn't passing. I get "Bummer! Hmm, the items don't seem to be sorted"
class Inventory:
def __init__(self):
self.slots = []
def add_item(self, item):
self.slots.append(item)
class SortedInventory(Inventory):
def add_item(self, item):
super().add_item(item)
self.slots.append(item)
self.slots.sort()
Chris Freeman
Treehouse Moderator 68,457 PointsYou are very very close! The overridden add_item method does not need the append operation since the call to super covers the append. Remove the extraneous append and it should pass.
Post back if you need more help. Good luck!!!
Jeremy Schaar
4,728 PointsGot it:) Thanks!