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 trialJacinto Jacinto
Python Web Development Techdegree Student 7,869 PointsCode works perfectly on my end but the quiz says otherwise.
On workspaces it works and on my command prompt it works. I am able to add items using the add_stuff method. I'll give you an example of a test I just did.
warehouse = SortedInventory()
warehouse.add_stuff("zebra")
warehouse.add_stuff("apple")
warehouse.slots
OUTPUT ["apple", "zebra"]
The code ended up sorting the list after apple was added. If it wasn't sorted then zebra would have been at index [0] and apple would have been in index [1].
At this point I don't know what to do and I don't want to look up an answer.
Thanks!
class Inventory:
def __init__(self):
self.slots = []
def add_item(self, item):
self.slots.append(item)
class SortedInventory(Inventory):
def add_stuff(self, item):
super().add_item(item)
self.slots.sort()
2 Answers
Jason Anders
Treehouse Moderator 145,860 PointsHi Jacinto,
It's not working, because you are not overriding the correct method.
I'm not sure why the code checker passed the code for Task #2 as you are using a different named method that is meant to override a parent method. Weird? (Tagging Kenneth Love to have a look )
In your SortedInventory Class, you have def add_stuff
when it should be def add_item
. Once you make that correction, all 3 tasks pass.
Keep Coding!
Jacinto Jacinto
Python Web Development Techdegree Student 7,869 PointsThank you! That helped a lot! I thought the quiz wanted me to override the parent class method with a different method. That's the reason why I decided to change the name. When it passed on Task #2 I thought I was on the right track. Honestly, does the name of the function even matter if it outputs the same result? In any case, I was stumped on this for quite a while. Thanks again for the quick response and help!
Kenneth Love
Treehouse Guest TeacherKenneth Love
Treehouse Guest TeacherThanks for pinging me on this. I've updated the CC to handle this kind of case.