Python Object-Oriented Python Inheritance Inheritance Quiz

Joshua Hovden
Joshua Hovden
2,979 Points

I don't understand why Orange().squeeze() wouldn't return True

Don't Orange objects have the has_pulp attirbute equal to True and doesn't the squeeze method return has_pulp?

2 Answers

The has_pulp is being returned through the squeeze function but is an attribute outside of the squeeze function.

class Orange:
    has_pulp = True

    def squeeze(self):
        return has_pulp

>>> Orange().squeeze()
#Traceback
#NameError: name 'has_pulp' is not defined 
 class Orange:
    def squeeze(self):
        has_pulp = True
        return has_pulp

>>> Orange().squeeze()
True
Michael MacDougall
seal-mask
.a{fill-rule:evenodd;}techdegree
Michael MacDougall
Full Stack JavaScript Techdegree Student 10,705 Points

Ran into the same issue on this problem and took me a while to figure out

From testing it there is a missing self on the has_pulp in the squeeze method.

To get the code running correctly make the following change to the original code:

class Orange(Fruit):
    has_pulp = True

    def squeeze(self):
        return self.has_pulp

Then run the python repl and see if that works.