Duane Smith1,673 Points
So I've kept at this challenge and I don't seem to know what I'm getting wrong. When I test my code in VSCode, it works.
It seems that I'm not seeing something in terms of what the question is specifically looking for. I got help from another user who pointed out some things, but I still wasn't able to bring it together. After tinkering with it after a few days, I came up with this code and it seems to work. When I enter the len function after I create a new instance of my class, It gives me the wrong value, which is what I want. So I don't know what I'm doing wrong.
Any help will be greatly appreciated.
Thank You in Advance,
import random class Liar(list): def __init__(self, value, *args, **kwargs): super().__len__() self.value = random.randint(0, value) def __len__(self): return self.value
Jennifer NordellTreehouse Staff
Hi there, Duane Smith! Way to keep at it! You're doing great. Part of the problem here is that you don't get to decide what gets passed in upon creating a new instance of
Liar() inside the challenge. The
Liar() class will only accept one argument and that is of type
You do not need to override the
__init__. You only need to override the
__len__() method here. Part of the inherent problem with returning a random value is that you cannot guarantee that the random number that was rolled does not accidentally match the actual length. For example, if I sent in
['a', 'b', 'c'] then that has a
len() that would return 3. But what happens if the random number it rolls is a 3? Then it's not lying
I'm expecting something more along the lines of this pseudocode:
class Liar(list): def __len__(self): # length = call super() then call __len__() # return length + 15
Hope this helps!