-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculator.py
More file actions
31 lines (30 loc) · 768 Bytes
/
calculator.py
File metadata and controls
31 lines (30 loc) · 768 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
def add(a,b):
return a+b
def subtract(a,b):
return a-b
def multiply(a,b):
return a*b
def divide(a,b):
return a/b
operations_dict = {
"+": add,
"-": subtract,
"*": multiply,
"/": divide
}
number1=int(input("enter first number: "))
for symbol in operations_dict:
print(symbol)
continue_flag=True
while continue_flag:
op_symbol=input("Pick an operation:")
number2=int(input("enter next number:"))
calculator_function=operations_dict[op_symbol]
output=calculator_function(number1,number2)
print(f"{number1} {op_symbol} {number2}={output}")
should_continue=input(f"Enter 'y' to continue calculation with {output} or 'n' to exit").lower()
if should_continue=='y':
number1=output
else:
continue_flag=False
print("Bye")