Skip to content

Commit 057df15

Browse files
committed
calculator.py
1 parent 1ced3b5 commit 057df15

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

calculator.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
def add(a,b):
2+
return a+b
3+
def subtract(a,b):
4+
return a-b
5+
def multiply(a,b):
6+
return a*b
7+
def divide(a,b):
8+
return a/b
9+
operations_dict = {
10+
"+": add,
11+
"-": subtract,
12+
"*": multiply,
13+
"/": divide
14+
}
15+
number1=int(input("enter first number: "))
16+
for symbol in operations_dict:
17+
print(symbol)
18+
continue_flag=True
19+
while continue_flag:
20+
op_symbol=input("Pick an operation:")
21+
number2=int(input("enter next number:"))
22+
calculator_function=operations_dict[op_symbol]
23+
output=calculator_function(number1,number2)
24+
print(f"{number1} {op_symbol} {number2}={output}")
25+
26+
should_continue=input(f"Enter 'y' to continue calculation with {output} or 'n' to exit").lower()
27+
if should_continue=='y':
28+
number1=output
29+
else:
30+
continue_flag=False
31+
print("Bye")

0 commit comments

Comments
 (0)