+ 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...

27th Feb 2017, 12:18 PM
Никита Кремнёв
Никита Кремнёв - avatar
5 Antworten
+ 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
27th Feb 2017, 12:41 PM
Никита Кремнёв
Никита Кремнёв - avatar
+ 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 :(
27th Feb 2017, 12:14 PM
Никита Кремнёв
Никита Кремнёв - avatar
+ 2
great thanks @StarLord, I'll try harder)
27th Feb 2017, 12:24 PM
Никита Кремнёв
Никита Кремнёв - avatar