Python Object-Oriented Python Advanced Objects Frustration

Greg Waitt
Greg Waitt
6,599 Points

Need help validating answer

The code passes the "quiz" but I am having trouble validating the code. The list is printed and not the "liar length". What am I doing wrong? Thanks for your help.

frustration.py
class Liar(list):
    def __len__(self):
        lie=super().__len__() +3
        return lie

test2 = Liar(['a','b','c','d'])
print(test2)
Daniel Nakonieczny
Daniel Nakonieczny
Pro Student 52,075 Points

I was playing with this in the terminal, and got this to work using python3:

frustration.py
class Liar(list):
    def len(self):
        lie=len(self)+3
        return lie

test2 = Liar(['a','b','c','d'])
print(test2.len()) #returns 7

1 Answer

Myers Carpenter
STAFF
Myers Carpenter
Treehouse Staff

Cool you are trying to make this work in the actual python REPL.

print(something) gets python to print out that something, but won't show the length. You want print(len(something)) to print the length.

Greg Waitt
Greg Waitt
6,599 Points

Thanks. I see now that the function returns len to the class. I cannot get the function result from calling the class directly (which is a list).