Skip to content

Instantly share code, notes, and snippets.

@StephenFordham
Created December 12, 2019 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StephenFordham/d62b97ac0ffb5af552579391287e8570 to your computer and use it in GitHub Desktop.
Save StephenFordham/d62b97ac0ffb5af552579391287e8570 to your computer and use it in GitHub Desktop.
class_NumOperations
class NumOperations(object):
def __init__(self, math_list):
self.math_list = math_list
def __sub__(self, other):
minuslst = []
zipped = zip(self.math_list, other.math_list)
for tup in zipped:
minuslst.append(tup[0] - tup[1])
return NumOperations(minuslst)
def __add__(self, other):
addlst = [x + y for x, y in zip(self.math_list, other.math_list)]
return NumOperations(addlst)
def __mul__(self, other):
mullst = [x * y for x, y in zip(self.math_list, other.math_list)]
return NumOperations(mullst)
def __repr__(self):
return str(self.math_list)
x = NumOperations([100, 90, 80, 70, 60])
y = NumOperations([10, 9, 8, 7, 6])
p = x - y
z = x + y
q = x * y
print('Subtraction: ' + str(p))
print('Addition: ' + str(z))
print('Multiplication: ' + str(q))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment