I have defined an object that will have an argument. Then I have created 3 methods as:
do_it1will add 10 on value of the objectdo_it2will add 20 on value of the objectdo_it3could accept an argument then it should add 30 plus its input argument on what's applied on.i.e. to what is on the left side.
Here's what I did
class MyClass():
def __init__(self,object_value):
self.object_value = object_value
def do_it1 (self):
return self.object_value + 10
def do_it2 (self):
return self.object_value + 20
def do_it3 (self,input_number):
self.input_number = input_number
return + 30 + self.input_number
here is the output
MyClass(5).do_it1()
returns 15 which is correct
MyClass(4).do_it2()
returns 24 which is correct
MyClass(4).do_it2().do_it3(6)
returns AttributeError: 'int' object has no attribute 'do_it3' while I was expecting 60 as 4 + 20 + 30 + 6
MyClass(1).do_it1().do_it2().do_it3(9)
returns AttributeError: 'int' object has no attribute 'do_it2' while I was expecting 1 + 10 + 20 + 30 + 9 = 70
How I could apply a method on top of method(s) in same class