Question: Program Plan: 1 . Artist.py: Class Artist: Constructor init: Initializes artist attributes: name, birth _ year, and death _ year. If not provided, defaults are

Program Plan:
1. Artist.py:
Class Artist:
Constructor init: Initializes artist attributes: name, birth_year, and death_year. If not provided, defaults are used.
Method print_info: Prints the artist's name, birth year, and death year or mentions "present" if the artist is still alive.
2. Artwork.py:
Import:
Import the Artist class from Artist.py.
Class Artwork:
Constructor init: Initializes artwork attributes: title, year_created, and the associated artist object.
Method print_info: Prints the artwork's title and year created. Calls the Artist's print_info method to print the artist's details.
3. main.py:
Main Function:
Reads user input for an artist's name, birth year, and death year.
Reads user input for artwork title and year of creation.
Creates an Artist object using the provided artist details.
Creates an Artwork object using the provided artwork details and the created Artist object.
Calls print_info on the Artwork object to display both artwork and artist information.
Step 2 of 2
The required code snippets are as follows:
Artist.py
class Artist:
# Constructor that initializes the Artist's name, birth year, and death year
def __init__(self, name = "unknown", birth_year =-1, death_year =-1)-> None:
# Assign name, birth year, and death year to the instance attributes
self.name = name
self.birth_year = birth_year
self.death_year = death_year
# Method to print the artist's information based on the provided birth and death years
def print_info(self):
# If both birth year and death year are valid, print them
if self.birth_year >0 and self.death_year >=0:
print(f'Artist: {self.name}({self.birth_year} to {self.death_year})')
# If only birth year is known and artist is still alive, print "present"
elif self.birth_year >=0:
print(f'Artist: {self.name},({self.birth_year}- present)')
# If no valid birth year is provided, print "unknown"
else:
print(f'Artist: {self.name}(unknown)')
Artwork.py
from Artist import Artist # Import the Artist class for use within Artwork
class Artwork:
# Constructor that initializes the title, year of creation, and associated artist
def __init__(self, title = "unknown", year_created =-1, artist = Artist())-> None:
# Assign title, year of creation, and associated artist to the instance attributes
self.title = title
self.year_created = year_created
self.artist = artist
# Method to print the artwork's information along with the artist's details
def print_info(self):
self.artist.print_info() # Call the artist's print_info method to display artist details
# Print the artwork's title and the year it was created
print(f'Title: {self.title},{self.year_created}')
Main.py
# Import the Artist and Artwork classes
from Artist import Artist
from Artwork import Artwork
# Entry point of the program
if __name__=="__main__":
# Read the artist's name from user input
user_artist_name = input()
# Read the artist's birth year from user input (converted to integer)
user_birth_year = int(input())
# Read the artist's death year from user input (converted to integer)
user_death_year = int(input())
# Read the artwork's title from user input
user_title = input()
# Read the year the artwork was created from user input (converted to integer)
user_year_created = int(input())
# Create an Artist object using the provided name, birth year, and death year
user_artist = Artist(user_artist_name, user_birth_year, user_death_year)
# Create an Artwork object using the title, year created, and the associated artist
new_artwork = Artwork(user_title, user_year_created, user_artist)
# Print the complete artwork information (including artist details)
new_artwork.print_info()
Final solution
The sample outputs are as follows:

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!