Answer:
class Artist():
def __init__(self, artist_name=None, artist_birth_year=0, artist_death_year=0):
self.artist_name = artist_name
self.artist_birth_year = artist_birth_year
self.artist_death_year = artist_death_year
def display_artist(self):
if self.artist_death_year == -1:
print('{}, born {}'.format(self.artist_name, self.artist_birth_year))
else:
print('{} ({}-{})'.format(self.artist_name, self.artist_birth_year, self.artist_death_year))
class Artwork():
def __init__(self, artwork_title=None, artwork_year_created=0, artist=Artist()):
self.artwork_title = artwork_title
self.artwork_year_created = artwork_year_created
self.artist = artist
def display_artist(self):
print('artwork_title: {}'.format(self.artwork_title))
print('Artist: ', end='')
self.artist.display_artist()
def main():
user_artist_name = input('Enter the name of artist: ')
user_birth_year = int(input('Enter birth year: '))
user_death_year = int(input('Enter death year: '))
user_title = input('Enter master piece title: ')
user_year_created = int(input('Enter year created: '))
user_artist = Artist(user_artist_name, user_birth_year, user_death_year)
new_artwork = Artwork(user_title, user_year_created, user_artist)
new_artwork.display_artist()
if __name__ == "__main__":
main()
Explanation:
- Inside the constructor of Artist class, initialize the essential properties.
- Create the display_artist function that checks whether artist_death_year is equal to -1 and then displays an appropriate message according to the condition.
- Apply the similar steps as above for the Artwork class.
- Inside the main method, get the information from user and finally call the display_artist function to print the results on screen.