-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathDay010-Basic-Calculator.py
58 lines (42 loc) · 971 Bytes
/
Day010-Basic-Calculator.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
from art import logo
from replit import clear
#Calculator
#Add
def add(n1,n2):
return n1 + n2
#Subtract
def subtract(n1,n2):
return n1 - n2
#Multiply
def multiply(n1,n2):
return n1 * n2
3
#Divide
def divide(n1,n2):
return n1 / n2
#Dictionary
operations = {
"+" : add,
"-" : subtract,
"*" : multiply,
"/" : divide,
}
def calculator():
print(logo)
num1 = float(input("What is the first number?\n"))
for symbol in operations:
print(symbol)
repeat = True
while repeat:
operation_symbol = (input("Pick an operation:\n"))
num2 = float(input("What is the next number?\n"))
calc_function = operations[operation_symbol]
answer = calc_function(num1,num2)
print(f"{num1} {operation_symbol} {num2} = {answer}")
if input(f"Type 'y' to continue calculating with {answer}, or type 'n' to exit.\n").lower() == "y":
num1 = answer
else:
repeat = False
clear()
calculator()
calculator()