-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
51 lines (32 loc) · 897 Bytes
/
test.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
# calculator
def add(n1, n2):
return n1 + n2
def subtract(n1, n2):
return n1 - n2
def multiply(n1, n2):
return n1 * n2
def divide(n1, n2):
return n1 / n2
operations = {
"+": add,
"-": subtract,
"*": multiply,
"/": divide
}
def calculator():
num1 = float(input("Enter the first number: "))
for operator in operations:
print(operator)
should_continue = True
while should_continue:
op_symbol = input("Pick an operation: ")
num2 = float(input("Enter the next number: "))
calculation = operations[op_symbol]
answer = calculation(num1, num2)
print(f"{num1} {op_symbol} {num2} = {answer}")
if input("Do you want to continue? type 'y' for Yes or 'n' for No: ") == 'y':
num1 = answer
else:
should_continue = False
calculator()
calculator()