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 trial

Python Object-Oriented Python Inheritance Super!

Jacinto Jacinto
seal-mask
.a{fill-rule:evenodd;}techdegree
Jacinto Jacinto
Python Web Development Techdegree Student 7,869 Points

Code 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!

inventory.py
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
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hi 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 :eyes:)

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! :dizzy:

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

Thanks for pinging me on this. I've updated the CC to handle this kind of case.

Jacinto Jacinto
seal-mask
.a{fill-rule:evenodd;}techdegree
Jacinto Jacinto
Python Web Development Techdegree Student 7,869 Points

Thank 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!