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:
Artist.py:
Class Artist:
Constructor init: Initializes artist attributes: name, birthyear, and deathyear. If not provided, defaults are used.
Method printinfo: Prints the artist's name, birth year, and death year or mentions "present" if the artist is still alive.
Artwork.py:
Import:
Import the Artist class from Artist.py
Class Artwork:
Constructor init: Initializes artwork attributes: title, yearcreated, and the associated artist object.
Method printinfo: Prints the artwork's title and year created. Calls the Artist's printinfo method to print the artist's details.
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 printinfo on the Artwork object to display both artwork and artist information.
Step of
The required code snippets are as follows:
Artist.py
class Artist:
# Constructor that initializes the Artist's name, birth year, and death year
def initself name "unknown", birthyear deathyear None:
# Assign name, birth year, and death year to the instance attributes
self.name name
self.birthyear birthyear
self.deathyear deathyear
# Method to print the artist's information based on the provided birth and death years
def printinfoself:
# If both birth year and death year are valid, print them
if self.birthyear and self.deathyear :
printfArtist: selfnameselfbirthyear to selfdeathyear
# If only birth year is known and artist is still alive, print "present"
elif self.birthyear :
printfArtist: selfnameselfbirthyear present
# If no valid birth year is provided, print "unknown"
else:
printfArtist: selfnameunknown
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 initself title "unknown", yearcreated artist Artist None:
# Assign title, year of creation, and associated artist to the instance attributes
self.title title
self.yearcreated yearcreated
self.artist artist
# Method to print the artwork's information along with the artist's details
def printinfoself:
self.artist.printinfo # Call the artist's printinfo method to display artist details
# Print the artwork's title and the year it was created
printfTitle: selftitleselfyearcreated
Main.py
# Import the Artist and Artwork classes
from Artist import Artist
from Artwork import Artwork
# Entry point of the program
if namemain:
# Read the artist's name from user input
userartistname input
# Read the artist's birth year from user input converted to integer
userbirthyear intinput
# Read the artist's death year from user input converted to integer
userdeathyear intinput
# Read the artwork's title from user input
usertitle input
# Read the year the artwork was created from user input converted to integer
useryearcreated intinput
# Create an Artist object using the provided name, birth year, and death year
userartist Artistuserartistname, userbirthyear, userdeathyear
# Create an Artwork object using the title, year created, and the associated artist
newartwork Artworkusertitle, useryearcreated, userartist
# Print the complete artwork information including artist details
newartwork.printinfo
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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
