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 trialnewpal
1,717 PointsWhat 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?
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
1 Answer
J llama
12,631 Pointsjust 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
dinomueller
8,996 PointsSame problem here!
David Mobley
5,574 PointsSame problem as well...
kgoldthorpe
7,802 Pointskgoldthorpe
7,802 PointsI 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.