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 trialPratham Mishra
14,191 PointsI am not able to understand the Task properly!
need help to understand the task
Create a new class named Liar that inherits from list. Override the len method so that it aways returns an incorrect number for the length. Inside of your len method use super() to call list's len method and return a modified version of the length. You won't need any arguments.
For example, if a list has two items in it, the Liar class could return a five. It should never return the correct length.
3 Answers
Nathan Garcia
9,098 PointsI understand how you feel. When you get lost like this, try to break down each of the things the instructor is asking and make sure you know the terms and ideas in each sentence.
Create a new class named Liar that inherits from list.
class Liar(list):
Override the len method so that it aways returns an incorrect number for the length.
So here you define a magic method with __len__
def __len__(self):
Inside of your len method use super() to call list's len method and return a modified version of the length. You won't need any arguments. For example, if a list has two items in it, the Liar class could return a five. This should be using super(), so the format would be
super().__len__()
It should never return the correct length. Here you have to change it so that always returns something different.
return super().__len__() + 1
Hope this helps. Good luck.
Steven Parker
231,248 PointsIt's a rather odd thing to do, but they want to you override the "len" method to always be wrong (perhaps for a prank?)
They even tell you how to implement it by "use super() to call list's len method" and then modify and return it.
Manish Kumar Meena
Python Development Techdegree Student 2,594 Points```class Liar(list):
def len(self):
super().len()
return super().len() + 1