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

What is wrong with my code please?

Now I want you to make a subclass of list. Name it Liar.

Override the len method so that it always returns the wrong number of items in the list. For example, if a list has 5 members, the Liar class might say it has 8 or 2.

You'll probably need super() for this.

frustration.py
class Liar(list):
    def __len__(self, list1):
        super().__len__()
        return (len(list1) - 2)

1 Answer

Alex Koumparos
seal-mask
.a{fill-rule:evenodd;}techdegree
Alex Koumparos
Python Development Techdegree Student 36,887 Points

Hi Ammar,

You've got the right general idea but the initialiser for len() doesn't take a value (it's operating on self, which is the list instance). This means you need to get rid of the list1 parameter.

Instead of working with list1, you will be working with the value that super's initialiser returns.

Hope that makes sense

Cheers

Alex

Thank you so much Alex! Changed my code based on your comments and now passes the check!