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!

not working error keys getting thrown when i enter self.slots.sort()

Not sure what is wrong here

inventory.py
class Inventory:
    def __init__(self):
        self.slots = []

    def add_item(self, item):
        self.slots.append(item)

class SortedInventory(Inventory):
    def __init__(self):
        super().__init__()

    def add_item(self,item):
        super(SortedInventory,self).add_item(item)
        self.slots.sort()
Nick B.
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Nick B.
Full Stack JavaScript Techdegree Graduate 31,101 Points

English is not my first language so please bare with me.

def __init__(self):
     super().__init__()

 def add_item(self,item):
     super(SortedInventory,self).add_item(item)
     self.slots.sort()

This is where things go wrong. You wanna don't need to use def init anymore here. Just go ahead and erase that. You wanna replace it with def add_item, call super after that then sort the list in the end

I'll give you a hint.

class SortedInventory(Inventory):
    def add_item(self,item):
    ...
    ...

1 Answer

Steven Parker
Steven Parker
231,275 Points

The arguments to "super" are unnecessary (and apparently ignored), as is the override of "__init__". But I tried pasting this code directly into the challenge with no changes and it passed.

Try restarting your browser, I've heard that can help in cases of "false failure".