Skip to content

Commit c905182

Browse files
Added basic arithmetic operations
1 parent ee6ece5 commit c905182

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

calculatorPlus.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import math
2+
3+
class Calculator:
4+
5+
def add(self, a, b):
6+
return a + b
7+
8+
def subtract(self, a, b):
9+
return a - b
10+
11+
def multiply(self, a, b):
12+
return a * b
13+
14+
def divide(self, a, b):
15+
return a / b
16+
17+
# TODO: Implement the following function to calculate the square root of a number.
18+
# def square_root(self, x):
19+
# return math.sqrt(x)
20+
21+
if __name__ == "__main__":
22+
calculator = Calculator()
23+
24+
num1 = 16
25+
num2 = 4
26+
27+
print(f"{num1} + {num2} = {calculator.add(num1, num2)}")
28+
print(f"{num1} - {num2} = {calculator.subtract(num1, num2)}")
29+
print(f"{num1} * {num2} = {calculator.multiply(num1, num2)}")
30+
print(f"{num1} / {num2} = {calculator.divide(num1, num2)}")
31+
32+
# TODO: Uncomment and test the square root feature.
33+
# num3 = 25
34+
# print(f"The square root of {num3} = {calculator.square_root(num3)}")

0 commit comments

Comments
 (0)