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 trialGreg Waitt
6,599 PointsNeed 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.
class Liar(list):
def __len__(self):
lie=super().__len__() +3
return lie
test2 = Liar(['a','b','c','d'])
print(test2)
1 Answer
Myers Carpenter
6,421 PointsCool 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
6,599 PointsThanks. 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).
Daniel Nakonieczny
Courses Plus Student 54,657 PointsDaniel Nakonieczny
Courses Plus Student 54,657 PointsI was playing with this in the terminal, and got this to work using python3: