+ 1

What's wrong with this code

class Description: def __init__(self,height,weight,age): self.height = height self.weight = weight self.age = age @property def isTall(self): if self.height > 175: return "Tall" else: return "False" @property def isHeavy(self): if self.weight > 80: return "Heavy" else: return "Not" @property def isOld(self): if self.age > 18: return "Kinda" else: return "Nah" VH = Description([180,78,19]) print(VH.isTall,VH.isHeavy,Vh.isOld)

25th Jun 2018, 7:26 AM
Hồng Vĩ
Hồng Vĩ - avatar
3 ответов
+ 4
#Line 9 to line 26 has to be indented to be included inside class Description. #Line 28 parameter is not a list but 3 different parameters. #There's also a typo on line 29 where VH is written as Vh. class Description: def __init__(self,height,weight,age): self.height = height self.weight = weight self.age = age @property def isTall(self): if self.height > 175: return "Tall" else: return "False" @property def isHeavy(self): if self.weight > 80: return "Heavy" else: return "Not" @property def isOld(self): if self.age > 18: return "Kinda" else: return "Nah" VH = Description(180,78,19) print(VH.isTall,VH.isHeavy,VH.isOld)
25th Jun 2018, 7:42 AM
Hatsy Rei
Hatsy Rei - avatar
+ 1
Your class expects 3 positional arguments: height, weight, age. When you initiate it, Description([...]), you are passing a single list argument. Now read the error, it should be clearer. One more thing, for better Python practice, try to give your classes less general name like Person.
25th Jun 2018, 7:45 AM
Qwertiony
Qwertiony - avatar
+ 1
thanks guys
25th Jun 2018, 7:54 AM
Hồng Vĩ
Hồng Vĩ - avatar