I have the following task to complete:
Making appropriate use of your Duration class write an MP3Song class to
model an MP3 song. Every song has an artist, a title and a duration. (Your
class must inherit only from object.) When your class is correctly
implemented, running the program below will produce the output that follows:
Making appropriate use of your Duration class write an MP3Song class to
model an MP3 song. Every song has an artist, a title and a duration. (Your
class must inherit only from object.) When your class is correctly
implemented, running the program below will produce the output that follows:
from exam_2018 import Duration, MP3Song d = Duration(6, 31) s1 = MP3Song('U2', 'Zooropa', d) s2 = MP3Song('U2', 'Ultraviolet') s3 = MP3Song('The National', 'Lucky You', Duration(3, 56)) print(s1) print(s2) print(s3)Expected output:
Output:$ python3 mp3song_demo.py
U2 : Zooropa (06:31)
U2 : Ultraviolet (00:00)
The National : Lucky You (03:56)
I am having trouble reading from s1 and s3 and the following code is what i have so far:class Duration(object): def __init__(self, minutes=00, seconds=00): self.minutes = minutes self.seconds = seconds def __str__(self): return("{:02d}:{:02d}".format(self.minutes, self.seconds)) def __gt__(self, other): return self.time_to_seconds() > other.time_to_seconds() def __eq__(self, other): return self.time_to_seconds() == other.time_to_seconds() def time_to_seconds(self): return(self.minutes * 60 + self.seconds) class MP3Song(object): def __init__(self, artist, title, duration=0): self.artist = artist self.title = title self.duration = duration def __str__(self): return("{:} : {:} ({:02d}:{:02d})".format( self.artist, self.title, self.duration, self.duration))I would greatly appreciate any help!