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 trial

Python

Frustration.py I passed it, but it is not totally clear

I passed the challenge python.py, but I don't understand totally why we do have to use the super() function. With the super() we are 'looking' for the len method result in the superclass: list. Is it not possible to pass the challenge without looking at the list class?

class Liar(list):
    def __len__(self):
        liar = super().__len__() + 1
        return liar

2 Answers

Steven Parker
Steven Parker
243,318 Points

The only way to guarantee the answer is always wrong, is to get the real answer from the base class and then change it.

Is it not the 'real' if I only consider the answer from my Liar class?

Steven Parker
Steven Parker
243,318 Points

But how will the Liar class give an answer without first getting it from the base class?

this is my 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
Steven Parker
243,318 Points

:warning: FYI: According to a moderator, explicit answers without any explanation are strongly discouraged by Treehouse.