-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path7_calculator_modified.py
59 lines (36 loc) · 1.12 KB
/
7_calculator_modified.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
52
53
54
55
56
57
58
59
from numpy import False_
print("Welcome to the CALCULATOR")
def add(first,second):
return first + second
def sub(first,second):
return first - second
def mul(first,second):
return first * second
def div(first,second):
return first / second
ops = {
'+' : add,
'-': sub,
'*': mul,
'/': div
}
def calculator():
num1 = float(input("What is the first number: "))
for key in ops:
print(key)
end_calc = False
while not end_calc:
op_choice = input("Please choose a operation from the list above: ")
num2 = float(input("What is the next number: "))
calc = ops[op_choice]
answer = calc(num1,num2)
print(f"{num1} {op_choice} {num2} = {answer}")
ex = input(f"Type 'y' to keep calculating with {answer}, 'n' to start a new calculation or 'e' to exit: ")
if ex == 'y':
num1 = answer
elif ex == 'n':
calculator()
elif ex == 'e':
end_calc = True
print("Goodbye")
calculator()