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 Object-Oriented Python Dice Roller Compare and Contrast

What is wrong with my code please?

I'd like to compare songs by their length (measured in whole seconds). Add the required methods for ==, <, >, <=, and >= comparisons. Probably a good idea to be able to convert Songs to ints, too, huh?

songs.py
class Song:
    def __init__(self, artist, title, length):
        self.artist = artist
        self.title = title
        self.length = length

    def __int__(self):
        return self.length

    def __eq__(self.length, other_song_length):
        return int(self.length) == other_song_length

    def __lt__(self.length, other_song_length):
        return int(self.length) < other_song_length

    def __gt__(self.length, other_song_length):
        return int(self.length) > other_song_length

    def __le__(self.length, other_song_length):
        return int(self.length) < other_song_length or int(self.length) == other_song_length

    def __ge__(self.length, other_song_length):
        return int(self.length) > other_song_length or int(self.length) == other_song_length

I have found this challenge to be very fickle. This worked for me, and it only worked for me when I copied it from someone else's answer in this forum. I typed this in verbatim and it didn't work, but when I copied and pasted the code, it worked.

    def __int__(self):
        return self.length

    def __eq__(self, other):
        return int(self) == other

    def __lt__(self, other):
        return int(self) < other

    def __gt__(self, other):
        return int(self) > other

    def __le__(self, other):
        return int(self) < other or int(self) == other

    def __ge__(self, other):
        return int(self) > other or int(self) == other

1 Answer

J llama
J llama
12,631 Points

just a joke of an assignment.... doesn't properly compile or something bc i had the exact same thing as other students. when i copy it it works fine.my vesion bombs

Same problem here!

David Mobley
David Mobley
5,574 Points

Same problem as well...