Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Problem: Notice that song_1 and song_2 have the same artist and label. That means they should each have the SAME instance of artist: do not create separate instances of artist for each song.
- '''
- class Artist:
- def __init__(self, name, label):
- self.name = name
- self.label = label
- class Song:
- def __init__(self, name, album, year, artist):
- self.name = name
- self.album = album
- self.year = year
- self.artist = artist
- #Write your code here!
- artist1 = Artist("Taylor Swift", "Big Machine Records, LLC")
- song_1 = Song("You Belong With Me", "Fearless", 2008, artist1)
- song_2 = Song("All Too Well", "Red", 2012, artist1)
- #Alternative way to reference song_1 artist since they belong to the same artist
- #song_2 = Song("All Too Well", "Red", 2012, song_1.artist)
- #We can also create a variable for artist2 and do it the same way as I did for song_1
- song_3 = Song("Up We Go", "Midnight Machines", 2016, Artist("LiGHTS", "Warner Bros. Records Inc."))
- #Feel free to add code to test your code below.
- print(song_1.artist.name)
- print(song_2.artist.label)
- print(song_3.artist.name)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement