Question
We are now finally able to model anAlbum. An album should be initialized with anArtistand a title. It should have the following properties: 1.artist: AnArtistobject
We are now finally able to model anAlbum. An album should be initialized with anArtistand a title.
It should have the following properties:
1.artist: AnArtistobject representing the Artist of the album.
2.title: Astrrepresenting the title of the album.
3.songs: Alistof songs in the album (Initially it is empty).
In addition, it should provide the following method:
1.add_song(self, song): Adds song (of classSong) to the album.
2.total_runtime(self): Returns the total runtime (of classDuration) of the album.
The example tests use aBandclass defined as follows:
class Band(Artist): def __init__(self, name, dob, members): super().__init__(name, dob) self.members = members def formation_age(self): return super().age() def age(self): total_age = 0 for member in self.members: total_age += member.age() return total_age / len(self.members)
NOTE:You may assume that theArtist,Duration,SongandBandclasses have been defined. You only need to submit code for theAlbumclass.
NOTE:Please only include the definition of theAlbumclass and nothing else. In particular, please remove all test cases you have added or those provided in the template. On submission, if you see any errors aboutArtist,Duration,SongorBandnot defined, like the following:
# Traceback (most recent call last): # in# NameError: name 'Artist' is not defined
then most probably you have included some test cases using the above mentioned classes. Please remove the offending code and resubmit.
song definition
class Song(object):
def __init__(self, artist, title, duration):
self.title = title
self.artist = artist
self.duration = duration
pass
def get_artist(self):
return self.artist
pass
def get_title(self):
return self.title
pass
def get_duration(self):
return self.duration
pass
class Duration(object):
def __init__(self, minutes, seconds):
self.minutes = minutes
self.seconds = seconds
def get_minutes(self):
if self.seconds > 60:
return self.minutes + 1
else:
return self.minutes
def get_seconds(self):
if self.seconds > 60:
return self.seconds - 60
else:
return self.seconds
@property
def total_seconds(self):# This part is wrong
return 60 * (self.get_minutes()) + self.get_seconds()
def __str__(self):
string = ""
if self.minutes < 10:
string = "0"
string += str(self.get_minutes())
string += ":"
if self.seconds < 10:
string += "0"
string += str(self.get_seconds())
return string
def __add__(self, object):
p = int(self.get_minutes() + object.get_minutes())
q = int(self.get_seconds() + object.get_seconds())
while q > 60:
p = p + 1
q = q - 60
return Duration(p,q)
i have the following code so far but am struggling with total runtime
class Album(object):
def __init__(self, artist, title):
self.artist = artist
self.title = title
self.songs = list()
def add_song(self, song):
self.songs.append(song)
def total_runtime(self):
time = 0
for song in self.songs:
time += song.get_Duration()
d = time
return Duration(d)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started