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 trialJuneau Lim
13,362 PointsQuestion about my Liar
question about my Liar When I did below, it didn't work.
class Liar(list):
def __len__(self):
truth = super().__len__()
return truth * 2 # error
However, when I changed the last line to +, it was ok.
return truth + 2 # OK
What is the difference? I have no idea.
1 Answer
Steven Parker
231,275 PointsThe challenge wants your function to always return an incorrect value (a "lie").
The problem with "truth * 2
" is that when the actual value is 0, your function will return the true value.
Juneau Lim
13,362 PointsJuneau Lim
13,362 PointsWow, that's a gotcha. I haven't think about that case. Thanks for the answer!
Juneau Lim
13,362 PointsJuneau Lim
13,362 PointsSorry I thought I did it. :-(