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.

Python Object-Oriented Python Dice Roller Compare and Contrast

Ryan Sands
Ryan Sands
4,543 Points

Not 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

songs.py
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
Robert Stefanic
35,157 Points

Well, 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.