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 Advanced Objects Frustration

Why isn't this working

Please help with this code challenge

frustration.py
class Liar(list):
    def len(self):
        return super().len + 7

6 Answers

boi
boi
14,241 Points

The purpose of super is to call a method from the parent class. So in your code, you called super().len(), so the len() is suppose to be a method? Why did you call the len() method?

Here do this, since you called a method from the parent call list, Check if there is a method called len() in there, type this in your console.

help(list)

Scroll through it until you find something similar to your version of len() and see that the super() you called, Is it calling the right method? or is something wrong with your version of len().

SPOILER DON'T SEE SOLUTION UNTIL NECESSARY READ ABOVE

SOLUTION:

class Liar(list):
    def __len__(self):
        return super().__len__() + 4

I would recommend that you get a proper understanding of the super()and magic methods before continuing further in the course.

boi
boi
14,241 Points

Since len is supposed to be a magic method, try using it as a magic method, your code is properly structured you are just missing a magic method. Give it a little try, If you still have problems that's okay just comment for help.

class Liar(list):
    def __len__(self):
        return self.super().len() + 7
    ```
what's wrong here

As boi already mentioned len is a magic method in this challenge task and you are missing something here:

return self.super().len() + 7

Also, you do not need to use self at all.

Am I missing list? Also here is my updated code

class Liar(list):
    def __len__(self):
        return super().len() + 4
boi
boi
14,241 Points

Your code is correct, all you have missing are 4 underscores. let me give you a hint (len).

Can someone link the super and magic methods video