Python Object-Oriented Python Advanced Objects Frustration

Help in frustration challenge

Hello,

I am having trouble with this task. I watched the previous videos and tried to construct the code in a way that I think does what the task wants me to do.

I am really not sure what I am doing wrong and could use some hints and guidance.

Thank you in advance.

frustration.py
class Liar(list):
    def __len__(self):
        super().__len__()
        for _ in self:
            return len(self) + 1

3 Answers

Ari Misha
Ari Misha
19,208 Points

Hiya Taejooncho! All ya have to do is call "super()" on "len" of parent class "list" and add any number to it and return it. So yeah you dont need a "for" loop for that.

class Liar(list):
    def __len__(self):
        return super().__len__() + 5

Hello Ari Misha! Thank you for your help. May I ask why? Is it because len function already does what my for loop is doing?

Ari Misha
Ari Misha
19,208 Points

Hiya! And Nope thats coz the challenge asked ya to override len() method and return anything other than the correct value for the len method. Thats what i added 5. You can add or subtract any number to return value of len(). And what you were doing wasnt even related to the challenge was askin'. (:

Hey thanks again!

I did not have the question about the adding part. I wanted to know why you did not have the for loop like I did.

Anthony Albertorio
Anthony Albertorio
21,635 Points

You are returning just one number: the length of the Liar subclass. So there is no need to iterate over the list and add 1 to each element. The only thing that needs to be changed is the length of the list.