'Continuous error in module: TypeError: Artist() takes no arguments

Working through an assignment, and have tried multiple changes to both the Class and the Module but I still am getting an error, "TypeError: Artist() takes no arguments".

The assignment states: 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 "None" and the years of birth and death to 0.

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 "None", the year created to 0, and the artist to use the Artist default constructor parameter values. Add an import statement to import the Artist class.

Add import statements to main.py to import the Artist and Artwork classes.

Ex:

If the input is: Pablo Picasso 1881 1973 Three Musicians 1921

the output is: Artist: Pablo Picasso (1881-1973) Title: Three Musicians, 1921

If the input is: Brice Marden 1938

Distant Muses 2000

the output is: Artist: Brice Marden, born 1938 Title: Distant Muses, 2000

My Code:

class Artist:

   def __init__(self, name ="None", birth_year = 0, death_year = 0):
       """
       Constructor to initialize the name, birth_year and death_year to specified values
       default of "None", 0 and 0 respectively
       """
       self.name = name
       self.birth_year = birth_year
       self.death_year = death_year
  
   def print_info(self):
       """
       Function to display the information of the Artist
       """
       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))
      
 #end of Artist.py     

from Artist import Artist
class Artwork:

   def __init__(self, title = "None", year_created = 0, user_artist = Artist()):
       """
       Constructor to initialize the title, year_created and artist to specified values
       default of "None", 0 and default artist respectively
       """
       self.title = title
       self.year_created = year_created
       self.artist = user_artist
  
    def print_info(self):
       """
       Function to display the information of the Artwork
       """
       self.artist.print_info() # display the information for Artist
       print("Title: %s, %d" % (self.title, self.year_created))
  
#end of Artwork.py     

from Artist import Artist
from Artwork import Artwork  

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()

   #end of main.py  

ERROR:
Traceback (most recent call last):
  File "main.py", line 54, in <module>
    user_artist = Artist(user_artist_name, user_birth_year, user_death_year)
TypeError: Artist() takes no arguments


Solution 1:[1]

Works fine for me, please make sure you code has proper indentation, it might be an indentation problem.

enter image description here

Solution 2:[2]

All of these need to be handled in their respective files inside the embedded interpreter. Makes sure to click the drop down menu and select and fill in the 3 files, main.py, artist.py and artwork.py.

I am dumb.

The code works, if you put it in the right places.

Solution 3:[3]

I can solve your problem.Put double underscore(__) before init like [__init__] but it will give error if you write [_init_].So, correct the code and write __init__ instead of _init_. Code is :

def __init__():

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Cute Panda
Solution 2 Theodore Milonski
Solution 3