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 trialCharles Van Way
5,814 PointsFrustration is well-named. I've used the following code in an IDE, and it works fine. But not in the question.
import random
class Liar(list):
def __len__(self, things):
self.things = things
return len(self.things) + random.randrange(-3,4, 6)
super().__len__(self, things)
import random
class Liar(list):
def __len__(self, things):
self.things = things
return len(self.things) + random.randrange(-3,4, 6)
super().__len__(self, things)
3 Answers
Steven Parker
231,248 PointsI'm not sure how you tested this successfully in your IDE, but I see a few issues:
-
__len__
should not take any arguments other than self -
__len__
should not be called with any arguments -
super().__len__()
should be the basis for creating a "guaranteed wrong" value - anything after a "return" statement is never executed
Charles Van Way
5,814 PointsThanks for suggestions. I'll work on this.
Nicholas Lim
Python Development Techdegree Student 6,055 PointsOK everybody here's the answer:
import random
import math
class Liar(list):
def __init__(self, *arg):
self.arg = []
def __len__(self):
super().__len__()
randomNum = random.randint(2, 9)
x = len(self.arg) + math.factorial(randomNum)
return x
Steven Parker
231,248 PointsFYI: According to a moderator, explicit answers without any explanation are strongly discouraged by Treehouse.