I am writing a program with Artist and Artwork classes and a main.py file to run both classes. First I want to define the Artist class in Artist.py with a constructor to initialize an artist's information. The constructor should by default initialize the artist's name to "unknown" and the years of birth and death to -1. Then define the Artwork class in Artwork.py with a constructor to initialize an artwork's information. The constructor should by default initialize the title to "unknown", the year created to -1, and the artist to use the Artist default constructor parameter values. Add an import statement to import the Artist class. Finally, add import statements to main.py to import the Artist and Artwork classes. I have a working program that outputs the information but when I put in -1 to get unknown it initializes with -1 instead of printing unknown. I also need to add a repeating question to the user if they would like to add another artist that reruns the program if they type yes and prints bye bye if they type no. This is the code I have so far: Artist.py class Artist: def __init__(self, name="unknown", birth_year=-1, death_year=-1): self.name = name self.birth_year = birth_year self.death_year = death_year def print_info(self): if self.death_year == -1: print('Artist: {}, born {}'.format(self.name, self.birth_year)) else: print('Artist: {} ({}-{})'.format(self.name, self.birth_year, self.death_year)) Artwork.py from Artist import Artist class Artwork: def __init__(self, user_title="unknown", year_created=-1, user_artist=Artist()): self.title = user_title self.year_created = year_created self.artist = user_artist def print_info(self): self.artist.print_info() print (f'Title: {self.title}, {self.year_created}') main.py from Artist import Artist from Artwork import Artwork if __name__ == "__main__": print("Enter the artist's information") user_artist_name = input() user_birth_year = input() user_death_year = input() print("Enter the artwork information") user_title = input() user_year_created = input() user_artist = Artist(user_artist_name, user_birth_year, user_death_year) new_artwork = Artwork(user_title, user_year_created, user_artist) new_artwork. print_info()
I am writing a program with Artist and Artwork classes and a main.py file to run both classes. First I want to define the Artist class in Artist.py with a constructor to initialize an
artist's information. The constructor should by default initialize the
artist's name to "unknown" and the years of birth and death to -1.
Then define the Artwork class in Artwork.py with a constructor to initialize an
artwork's information. The constructor should by default initialize the
title to "unknown", the year created to -1, and the artist to use the Artist
default constructor parameter values. Add an import statement to import the
Artist class.
Finally, add import statements to main.py to import the Artist and Artwork classes.
I have a working program that outputs the information but when I put in -1 to get unknown it initializes with -1 instead of printing unknown. I also need to add a repeating question to the user if they would like to add another artist that reruns the program if they type yes and prints bye bye if they type no.
This is the code I have so far:
Artist.py
class Artist:
def __init__(self, name="unknown", birth_year=-1, death_year=-1):
self.name = name
self.birth_year = birth_year
self.death_year = death_year
def print_info(self):
if self.death_year == -1:
print('Artist: {}, born {}'.format(self.name, self.birth_year))
else:
print('Artist: {} ({}-{})'.format(self.name, self.birth_year, self.death_year))
Artwork.py
from Artist import Artist
class Artwork:
def __init__(self, user_title="unknown", year_created=-1, user_artist=Artist()):
self.title = user_title
self.year_created = year_created
self.artist = user_artist
def print_info(self):
self.artist.print_info()
print (f'Title: {self.title}, {self.year_created}')
main.py
from Artist import Artist
from Artwork import Artwork
if __name__ == "__main__":
print("Enter the artist's information")
user_artist_name = input()
user_birth_year = input()
user_death_year = input()
print("Enter the artwork information")
user_title = input()
user_year_created = input()
user_artist = Artist(user_artist_name, user_birth_year, user_death_year)
new_artwork = Artwork(user_title, user_year_created, user_artist)
new_artwork. print_info()
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 4 images