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

Steven Tagawa
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Steven Tagawa
Python Development Techdegree Graduate 14,438 Points

Why doesn't this work?

Task 2 of 3 tripped me up for quite a while, thinking there was something wrong with the logic, or for some reason the items couldn't be accessed by index number... Eventually I passed it by going the long way around:

def doubles(self):
    if self[0] == self[1]:
        return True
    else:
        return False

What I originally tried to do, which didn't work, was to return the expression directly:

        return (self[0] == self[1])

Since the expression obviously evaluates to either True or False, I have no clue why just returning it didn't work.

This also got me an earlier challenge in this course (don't remember which one now), where I had to assign an expression to a variable and then return the variable instead of returning the expression directly. So, can any Python master explain why this technique doesn't work?

1 Answer

Steven Parker
Steven Parker
231,269 Points

I'm not sure why you had trouble with that. You didn't show the whole code, but assuming you implemented it correctly as a property, that's exactly what I did and it passed the task.

If you still can't get it to work, be sure to show the whole code for a complete analysis.