Create a class called Numbers, which has a single class attribute called MULTIPLIER, and a constructor which
takes the parameters x and y (these should all be numbers).
(a) Write a method called add which returns the sum of the attributes x and y.
(b) Write a class method called multiply, which takes a single number parameter a and returns the product
of a and MULTIPLIER.
(c) Write a static method called subtract, which takes two number parameters, b and c, and returns b - c.
(d) Write a method called value which returns a tuple containing the values of x and y. Make this method
into a property, and write a setter and a deleter for manipulating the values of x and y.
class Numbers:
x = 0
y = 0
answer = 0
# parameterized constructor
def __init__(self, x, y):
self.x = x
self.y = y
def MULTIPLIER(self):
self.answer = self.x * self.y
return self.answer
num = Numbers(4, 5)
num.MULTIPLIER()
Comments
Leave a comment