-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalculator.py
53 lines (39 loc) · 1.15 KB
/
Calculator.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
44
45
46
47
48
49
50
51
52
53
def addition(n1, n2):
add = n1 + n2
return add
def subtraction(n1, n2):
subtract = n1 - n2
return subtract
def multiplication(n1, n2):
multiply = n1 * n2
return multiply
def division(n1, n2):
divide = n1 / n2
return divide
calculations = {
"+": addition,
"-": subtraction,
"*": multiplication,
"/": division,
}
def calculator():
print("Welcome to Calculator")
calculator_on = True
answer_1 = 0
while calculator_on:
n1 = int(input("Enter the number : "))
still_on = True
while still_on:
for symbol in calculations:
print(symbol)
function = input("Pick an operation from the above : ")
n2 = int(input("Enter the next number : "))
operation = calculations[function]
answer_1 = operation(n1, n2)
print(f"{n1} {function} {n2} = {answer_1}")
if input("Do you want to continue : ") == "n":
still_on = False
calculator_on = False
calculator()
n1 = answer_1
calculator()