Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
Why is this False
( If you are wondering I put in the comments, they were not there before and the comments are what I think is happening in this code)
class Orange(Fruit): #Orange is a new class with the parent class of Fruit has_pulp = True # The attribute has_pulp results in true def squeeze(self): # This is a new method in the Orange class return has_pulp # The method returns the result of has_pulp which is True
The question says Orange().squeeze() will return True. I entered true as my answer and it says it is incorrect, can someone explain to me why? Is it because of the parenthesis after Orange?
Steven Parker210,130 Points
The issue here is that since the "squeeze" method returns "
has_pulp" and not "
self.has_pulp" we don't have any information to really know what it will return. It might return
True, if perhaps there's a global variable (not shown here) that was also set to
True. It could just as easily have been set to
False. Or perhaps it is not defined and the function will cause a NameError exception.
So since we can't say for sure that it will return
True, the statement itself is then false.