|
| 1 | +class Song: |
| 2 | + def __init__(self, artist, duration, title): |
| 3 | + self.artist = artist # should be a string |
| 4 | + self.duration = duration # should be an integer in seconds |
| 5 | + self.title = title # should be a string |
| 6 | + |
| 7 | + def __str__(self): |
| 8 | + return f"{self.artist} - {self.title} ({self.duration})" |
| 9 | + |
| 10 | +class TalkShow: |
| 11 | + def __init__(self, host, guests, duration, title): |
| 12 | + self.host = host # should be a string |
| 13 | + self.guests = guests # should be a list of strings |
| 14 | + self.duration = duration # should be an integer in seconds |
| 15 | + self.title = title # should be a string |
| 16 | + |
| 17 | +class Playlist: |
| 18 | + def __init__(self, items): |
| 19 | + self.items = items # A list of Song or TalkShow |
| 20 | + self.currently_playing_index = 0 |
| 21 | + |
| 22 | + def play_next(self): |
| 23 | + pass |
| 24 | + # TODO: increment the currently_playing_index, when you get to the end loop back to 0 |
| 25 | + |
| 26 | + def get_currently_playing(self): |
| 27 | + return "todo" |
| 28 | + # TODO: return a string representation of whatever is playing at the current index |
| 29 | + # See the __str__ method in Song for an example of how to make a string representation of a class |
| 30 | + |
| 31 | + def get_total_duration(self): |
| 32 | + return 0 |
| 33 | + # TODO: return |
| 34 | + |
| 35 | +song_a = Song("Rick Astley", 210, "Never Gonna Give You Up") |
| 36 | +print(song_a) |
| 37 | + |
| 38 | +song_b = Song("Psy", 219, "Gangnam Style") |
| 39 | +funny_songs = Playlist([song_a, song_b]) |
| 40 | +print(funny_songs.get_currently_playing()) |
| 41 | + |
| 42 | +show_a = TalkShow("Melvyn Bragg", ["Jim Al-Khalili", "Sheila Rowan", "Carolin Crawford"], 2700, "Gravitational Waves") |
| 43 | + |
0 commit comments