Reputation: 25
I have just started learning to program in Python. I am finding it difficult to instance objects properly. It gives a traceback but I don't know why. I have been reading the documentation for 3.8 and still not sure what is causing the error? Your help is deeply appreciated.
Thank you.
def _init_(self, name, age, character):
self.name = name
self.age = age
self.character = character
def date_of_birth():
return 2020 - self.age
Breeds = Breeds = [Dog("Alsation", 2,["Protective","Smart"]), Dog("Rotteweiler", 3,["Possessive","Aggressive"]), Dog("Chihuahua",1,["Loud, Jumpy"])]
sum = 0
for dog in Breeds:
sum = sum + Dog.age
print("The average age of breeds is: " + str(sum/len(Breeds)))'''
```Traceback (most recent call last):
File "C:\Users\Hilary\Desktop\hello.py", line 12, in <module>
Breeds = Breeds = [Dog("Alsation", 2,["Protective","Smart"]), Dog("Rotteweiler", 3,["Possessive","Aggressive"]), Dog("Chihuahua",1,["Loud, Jumpy"])]
TypeError: Dog() takes no arguments
>>> ```
Upvotes: 0
Views: 68
Reputation: 974
The __init__
method requires 2 underscores left and right, you are using 1.
Therefore your init method isn't recognized, and Python doesn't see any constructors that take your number of arguments.
Upvotes: 1