forked from fenyx-it-academy/Class5-Python-Module-Week5
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestion3.py
More file actions
29 lines (25 loc) · 1.1 KB
/
Question3.py
File metadata and controls
29 lines (25 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
'''## Question 3:
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).
* Write a method called `add` which returns the sum of the attributes `x` and `y`.
* Write a class method called `multiply`, which takes a single number parameter `a` and returns the product of `a` and `multiplier`.
* Write a method called `subtract`, which takes two number parameters, `b` and `c`, and returns `b - c`.
* Write a method called `value` which returns a tuple containing the values of `x` and `y`.
* Create a numbers object and call all the methods you wrote and print the results.
*'''
class Numbers:
def __init__(self, x, y):
self.x = x
self.y = y
def add(self):
return self.x + self.y
def multiply(self, a, multiplier):
return a *multiplier
def subtract(self, b, c):
return b-c
def value(self):
return (self.x, self.y)
number = Numbers(13,4)
print(number.add())
print(number.multiply(13,4))
print(number.subtract(13,4))
print(number.value())