+ 2
please help me to understand whats wrong [TypeError and more ;( ]
hi 2 all. may somebody explain me what's wrong in this code? it puts me a TypeError class Family: def __init__(self,status,age,function, hobby): self.status=status self.age=age self.function=function it puts me an error: Mommy = Family("Mom", 37 , "Love, Peace, Dinner" , "Flowers" ) Dad = Family("Dad" , 43 , "Power, Action, Sport" , "Hunting & Fishing" ) DadAge = Dad.age() print (DadAge) Traceback (most recent call last): File "..\Playground\", line 12, in <module> DadAge = Dad.age() TypeError: 'int' object is not callable -------------------------------------------- but I set attributes such as shown at SL lessons soon (I'm beginner in Python). maybe trouble in spaces? or not...
5 Réponses
+ 4
I fixed that!
class Family:
def __init__(self,status,age,function, hobby):
self.status=status
self.age=age
self.function=function
self.hobby=hobby
Dad = Family("Dad" , 43 , "Power, Action, Sport" , "Hunting & Fishing" )
DadAge = Dad.age # age is not an method so no parentheses required print (DadAge)
print (DadAge)
-------------------------
We should be careful with whitespaces xD
+ 2
i checked spaces in this code and TypeError was dissapeared/
class Family:
def __init__(self,status,age,function, hobby):
self.status=status
self.age=age
self.function=function
Mommy = Family("Mom", 37 , "Love" , "Flowers" )
Dad = Family("Dad" , 43 , "Power" , "Hunting & Fishing" )
DadAge = Dad.age()
print (DadAge)
BUT now it puts me:
File "..\Playground\", line 8
Mommy = Family("Mom", 37 , "Love" , "Flowers" )
^
IndentationError: unindent does not match any outer indentation level
-------------------------------------------
I need somebody to explain :(
+ 2
great thanks @StarLord, I'll try harder)