-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculator.py
More file actions
40 lines (35 loc) · 806 Bytes
/
calculator.py
File metadata and controls
40 lines (35 loc) · 806 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
32
33
34
35
36
37
38
39
40
def calculator():
def add(n1, n2):
return n1 + n2
def sub(n1, n2):
return (n1) - (n2)
def mult(n1, n2):
return n1 * n2
def div(n1, n2):
return n1 / n2
operations = {
"+": add,
"-": sub,
"*": mult,
"/": div,
}
go = True
count = 0
num1 = int(input("What is the first number? "))
for key in operations:
print(key)
while go:
symbol = input("Pick an operation: ")
num2 = int(input("What's the next number? "))
answer = operations[symbol](num1, num2)
print(f"{num1} {symbol} {num2} = {answer}")
count += 1
if count == 5:
clear()
count = 0
if input("Would you like to continue calculating? y/n\n") == "y":
num1 = answer
continue
else:
break
calculator()