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 trialRyan Sands
4,543 PointsNot sure how to complete songs.py (Compare and Contrast) python O.O challenge... Please help!!
I am not sure how to complete this please help me! Thanks
class Song:
def __init__(self, artist, title, length):
self.artist = artist
self.title = title
self.length = length
songs = self.artist, self.lenth, self.title
def __eq__(songs, other):
return int(songs) == other
def __le__(songs, other):
return int(songs) < other or int(songs) == other
def __ge__(songs, other):
return int(songs) > other or int(songs) == other
1 Answer
Robert Stefanic
35,170 PointsWell, there are a couple of things here.
(1.) There's a typo in your init.
In "songs = self.artist, self.lenth, self.title
" you have "length" spelled wrong.
(2.) You're trying to cast "songs
" into an integer, but "songs
" isn't the type of thing that can be cast as an integer. int()
takes a string and casts it to an integer, but "songs
" is a tuple. You can either extract the relevant values out of the tuple or you can rewrite the class so it separates the variables that you need.
If you get stuck again, then let me know, and I'll try and help you.