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

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.

import random

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

1 Answer

Steven Parker
Steven Parker
229,582 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.