I'm fixing a code to output artwork labels: class Artist: def __init__(self, name=str(None), birth_year=0, death_year=0): self.name = name self.birth_year = birth_year self.death_year = death_year def print_info(self): if self.birth_year < 0: print(f'Artist: {self.name} (unknown)') elif self.death_year < 0: print (f'Artist: {self.name} ({self.birth_year} to present)') else: print (f'Artist: {self.name} ({self.birth_year} to {self.death_year})') class Artwork: def __init__(self, title=str(None), year_created=0, artist=Artist()): self.title = title self.year_created = year_created self.artist = artist def print_info(self): self.artist.print_info() print (f'Title: {self.title}, {self.year_created}') if __name__ == "__main__": user_artist_name = input() user_birth_year = int(input()) user_death_year = int(input()) user_title = input() user_year_created = int(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() if I test Artist('Pablo Picasso', 1881, 1973) it correctly initializes the artist if I test artist constructor with default parameters values it outputs: Artist improperly initialized with constructor parameters defaults. name is: None birth_year is: 0 death_year is: 0 Any idea what's going on with the default parameters?
I'm fixing a code to output artwork labels:
class Artist:
def __init__(self, name=str(None), birth_year=0, death_year=0):
self.name = name
self.birth_year = birth_year
self.death_year = death_year
def print_info(self):
if self.birth_year < 0:
print(f'Artist: {self.name} (unknown)')
elif self.death_year < 0:
print (f'Artist: {self.name} ({self.birth_year} to present)')
else:
print (f'Artist: {self.name} ({self.birth_year} to {self.death_year})')
class Artwork:
def __init__(self, title=str(None), year_created=0, artist=Artist()):
self.title = title
self.year_created = year_created
self.artist = artist
def print_info(self):
self.artist.print_info()
print (f'Title: {self.title}, {self.year_created}')
if __name__ == "__main__":
user_artist_name = input()
user_birth_year = int(input())
user_death_year = int(input())
user_title = input()
user_year_created = int(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()
if I test Artist('Pablo Picasso', 1881, 1973)
it correctly initializes the artist
if I test artist constructor with default parameters values it outputs:
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 4 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)