q = obj_inside_1 + obj_inside_2
TypeError: unsupported operand type(s) for +: 'NoneType' and 'NoneType'
# -*- coding: utf-8 -*-
class math_operations:
def __init__(self, x, y):
self.x = x
self.y = y
print("\nobject inititalized\n")
def __add__(self, other): # self -> first instance = obj, other -> second instance = obj2
print (self.x + other.y * 10)
class child_math_operations(math_operations):
def Start(self, x1, y1, flag):
self.x1 = x1
self.y1 = y1
z1 = 10
h1 = 20
self.flag = flag # for choose
print("\nsecond type of object initialized\n")
if self.flag > 0:
obj_inside_1 = super().__init__(self.x1, self.y1)
obj_inside_2 = super().__init__(z1, h1)
q = obj_inside_1 + obj_inside_2
print(q)
else:
def __add__(self): # self -> first instance = obj, other -> second instance = obj2
return self.x1 + self.y1 * 10
def main():
obj = math_operations(1, 2)
obj2 = math_operations(0.1, 0.2)
c = obj + obj2
print(c)
obj_0_1 = child_math_operations(100, 20000)
obj_0_1.Start (100, 20000, 1)
x = obj_0_1 + obj_0_1
print(x)
if __name__ == '__main__':
main()