-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculatorPlus.py
More file actions
38 lines (26 loc) · 942 Bytes
/
calculatorPlus.py
File metadata and controls
38 lines (26 loc) · 942 Bytes
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
import math
class Calculator:
def add(self, a, b):
return a + b
def subtract(self, a, b):
return a - b
def multiply(self, a, b):
return a * b
def divide(self, a, b):
if b == 0:
raise ValueError("Cannot divide by zero.")
return a / b
# TODO: Implement the following function to calculate the square root of a number.
def square_root(self, x):
return math.sqrt(x)
if __name__ == "__main__":
calculator = Calculator()
num1 = 16
num2 = 4
print(f"{num1} + {num2} = {calculator.add(num1, num2)}")
print(f"{num1} - {num2} = {calculator.subtract(num1, num2)}")
print(f"{num1} * {num2} = {calculator.multiply(num1, num2)}")
print(f"{num1} / {num2} = {calculator.divide(num1, num2)}")
# TODO: Uncomment and test the square root feature.
num3 = 25
print(f"The square root of {num3} = {calculator.square_root(num3)}")