I know this may be a dumb question, but I am having a difficult time figuring out the error. I created a class called User to print out the first and last name, that's it. But when I try running it, it's giving me a typerror.
class User():def _init_(self, first_name, last_name):self.first_name = first_nameself.last_name = last_namedef describe_user(self):print("Your name is " + self.first_name.title() + ", " + self.last_name.title())
user_name = User('Andy', 'Wang')
user_name.describe_user()
The error is as follows:
File "c:\Users\Andy Wang\Documents\PCC\chap7.py", line 291, in <module>user_name = User('Andy', 'Wang')
TypeError: User() takes no arguments
I have made a similar program, but this time describing a restaurant and it works fine:
class Restaurant():def __init__(self, restaurant_name, cuisine_type):self.restaurant_name = restaurant_nameself.cuisine_type = cuisine_typedef describe_restaurant(self):print("\nThe restaraunt is called " + self.restaurant_name.title() + ".")print("It serves " + self.cuisine_type.title() + " food.")def open_restaurant(self):print(self.restaurant_name + " is open!\n")restaraunt = Restaurant('Szechuan Ichiban', 'Chinese')
restaraunt.describe_restaurant()
restaraunt.open_restaurant()
So I am just confused as to why the restaurant class works but my user class does not.
Thank you all for the help!