forked from MAZOUZBANK/functional_test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exercice1.py
43 lines (35 loc) · 963 Bytes
/
exercice1.py
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
class Calculator:
def __init__(self):
self.memory = 0
def add(self, a, b):
result = a + b
self.memory = result
return result
def subtract(self, a, b):
result = a - b
self.memory = result
return result
def multiply(self, a, b):
result = a * b
self.memory = result
return result
def divide(self, a, b):
if b == 0:
raise ValueError("Cannot divide by zero")
result = a / b
self.memory = result
return result
def power(self, a, b):
result = a ** b
self.memory = result
return result
def sqrt(self, a):
if a < 0:
raise ValueError("Cannot calculate square root of a negative number")
result = a ** 0.5
self.memory = result
return result
def clear_memory(self):
self.memory = 0
def get_memory(self):
return self.memory