-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalc.py
34 lines (29 loc) · 1.03 KB
/
calc.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
def add(num1,num2):
return num1 + num2
def subtract(num1,num2):
return num1-num2
def multiply(num1,num2):
return num1*num2
def divide(num1,num2):
return num1/num2
# taking the input from the user about the numbers
num1 = eval(input("Enter the first number : "))
num2 = eval(input("Enter the second number : "))
while(True):
operations = {"+":add,"-":subtract,"*":multiply,"/":divide}
for symbols in operations:
print(symbols,end=" ")
symbol = input("Choose a operation : ")
answer = operations[symbol](num1,num2)
print(f"{num1} {symbol} {num2} = {answer}")
breakout = input("Do you want to continue ?(yes/no)").lower()
if(breakout != "no"):
loop = input(f"Do you want to continue with {answer} ?(yes/no)").lower()
if(loop=="yes"):
num1 = answer
num2 = eval(input("Enter the second number : "))
else:
num1 = eval(input("Enter the first number : "))
num2 = eval(input("Enter the second number : "))
else:
break