-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculators_2.py
More file actions
38 lines (36 loc) · 1.07 KB
/
calculators_2.py
File metadata and controls
38 lines (36 loc) · 1.07 KB
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
def calculation ():
while True:
def add (a,b):
return a+b
def sub (a,b):
return a-b
def mult (a,b):
return a*b
def divi (a,b):
return a/b
operators={
"+":add,
"-":sub,
"*":mult,
"/":divi
}
fr_no=int(input("enter a frist number"))
for symbol in operators:
print(symbol)
flag=True
while flag:
choice=input("pick any the symbol")
se_no=int(input("enter a second number"))
calculator_fun=operators[choice]
output=calculator_fun(fr_no,se_no)
print(f"{fr_no} {choice} {se_no}={output}")
next_1=input("enter 'y' to continue calculation with {output} or 'n' to start 'e' to exit").lower()
if next_1=='y':
fr_no=output
elif next_1 == 'n':
break
elif next_1 =='e':
return
else:
print ("i navild choice")
print( calculation())