Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Object-Oriented Python Advanced Objects Frustration

I don't understand where I'm getting this wrong

Override the len method so that it always returns the wrong number of items in the list.

frustration.py
import random

class Liar(list):
    def __len__(self):
        super().__len__(self)
        return self + bool(random.randint(-3, 3))

1 Answer

Steven Parker
Steven Parker
210,936 Points

The message "Bummer: TypeError: expected 0 arguments, got 1" is a clue that you're passing an argument to a method that doesn't take any. In this case, it's passing "self" to "__len__", since the "self" parameter is handled internally and isn't passed explicitly.

Also, your return calculation doesn't make sense, it's attemptling combine a list (self) with a boolean. But what's needed here is simple since you only want to be sure to always give a wrong length. So you might just return the actual length (obtained with "super") with some value (constant, no need for anything random) added to it.