Getting "'tuple' object has no attribute 'perimetre'?"
How to resolve the problem? I try:
class plot():
def __init__(self,length,width):
self.length = length
self.width = width
def area(self):
print("area is ",self.length*self.width)
def perimetre(self):
per = 2(self.length+self.width)
print("perimeter is ",per)
a1 , p1 = plot(10,20),(10,20)
a1.area()
p1.perimetre()
and got this error:
<>:10: SyntaxWarning: 'int' object is not callable; perhaps you missed a comma?
<>:10: SyntaxWarning: 'int' object is not callable; perhaps you missed a comma? <ipython-input-83-8515c6a74849>:10: SyntaxWarning: 'int' object is not callable; perhaps you missed a comma?
per = 2(self.length + self.width)
--------------------------------------------------------------------------- AttributeError
Traceback (most recent call last)
<ipython-input-83-8515c6a74849> in <module>
13
14 a1.area()
---> 15 p1.perimetre()
AttributeError: 'tuple' object has no attribute 'perimetre'
Solution 1:
Change a1, p1 = plot(10,20),(10,20)
to a1, p1 = plot(10,20), plot(10,20)
. You are instantiating a plot
for a1
but then you instantiate a tuple for p1
by only using parentheses.
Also this code here per = 2(self.length+self.width)
is not valid. You're trying to call 2
like its a function.