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 trialKevin Selagea
2,161 PointsWhat do I do now?
I don't get what I did wrong.
class Inventory:
def __init__(self):
self.slots = []
def add_item(self, item):
self.slots.append(item
class SortedInventory:
slot = 0
def add_item(self, item):
super().add_item(item)
def __init__(self):
super().__init__()
slot.sort()
3 Answers
AJ Salmon
5,675 PointsHi Kevin,
Couple problems, but they're easy to fix!
- In your SortedInventory class, firstly, you need to make sure it inherits from the Inventory class. You would've had to have it do that to pass the first two tasks, so re-add it in there.
- Next, you won't need init in SortedInventory.
- The only method will be the add_item function.
- You also don't need a slot variable in the SortedInventory class.
- After your super(), all you have to do is sort the slots list with sort().
Hopefully this doesn't give too much away, if you need any more clarification feel free to ask!
Steven Parker
231,261 PointsFor task 1, you only need to "create a new class, SortedInventory that should be a subclass of Inventory".
So you still need to revise your class declaration to indicate that is extends "Inventory".
Also, you have a bunch of extra code there that's not related to this challenge. In particular, you won't need to override "__init__
" for this one.
The secret to the challenges is to do only what the instructions ask for!
Todd Anderson
4,260 PointsHi!
I'm not sure how you got past step one without inheriting inventory, but we'll figure it out. :)
So you need to inherit inventory in the parameter of your subclass like so.
class SortedInventory(Inventory):
this give you everything from the Inventory class.
Most of your code looks right except you do not need a new slot list, you are inheriting the one created in your original class when you override your init with super().init()
From there you just have to fix your syntax error by calling the sort method on your original slot list.
I hope that helps.
SPOILER ANSWER CODE:
class SortedInventory(Inventory):
def add_item(self, item):
super().add_item(item)
def __init__(self):
super().__init__()
slots.sort()
Steven Parker
231,261 Points I think you have the wrong challenge! This one does not involve overriding "__init__
"!
And this "spoiler" will not get a pass beyond task 1.