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!

Can Someone help me please?

I'm a bit confused as to what exactly I need to do. I need some help.

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

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

3 Answers

Greg Kaleka
Greg Kaleka
39,021 Points

Hi Kevin,

Are you still on task 1? If so, you need to create a whole new class, called SortedInventory. It should be a subclass of Inventory. No need to change anything about the Inventory class (I see you've added a call to super() in both methods - don't do that. Inventory doesn't have a superclass!).

I did, and this is what I got.

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()
Steven Parker
Steven Parker
231,261 Points

In this challenge, you'll be building a new class that extends the "Inventory" class provided. You will not be modifying the Inventory class itself. So you should restart or put it back the way it was.

Then for the first task, you just "create a new class, SortedInventory that should be a subclass of Inventory."

I did, and this is what I got. It's still not passing.

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()
Steven Parker
Steven Parker
231,261 Points

You still need to revise your class declaration to indicate that is extends "Inventory".

And the class definition needs to start against the left margin. No indentation on that line.

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
Todd Anderson
4,260 Points

Hi.

Is your actual code indented like above? If so unindent your class SortedInventory. Also you do not need a new slot variable, and you need to inherit Inventory from your first class

class SortedInventory(Inventory):

Cheers

Todd Anderson
Todd Anderson
4,260 Points

Also make sure you call sort on the original slots list

slots.sort()