-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
52 lines (42 loc) · 1.06 KB
/
main.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
from art import logo
def add(n1, n2):
return n1 + n2
def subtract(n1, n2):
return n1 - n2
def multiply(n1, n2):
return n1 * n2
def divide(n1, n2):
return n1 / n2
operations = {
'+': add,
'-': subtract,
'*': multiply,
'/': divide,
}
def calculator():
print(logo)
num1 = float(input("What is the first number?: "))
run = True
while run:
for e in operations:
print(e)
perform = input("Type a math operation: ")
num2 = float(input("What is the next number?: "))
calculation = operations[perform]
answer = calculation(num1, num2)
print(f"{num1} {perform} {num2} = {answer}")
print(f"Type 'y' to continue calculating with {answer}, type 'n' to exit or type 'new' for a brand new calculation")
continue_calc = input("Type y/n/new: ")
if continue_calc == 'y':
run = True
num1 = answer
elif continue_calc == 'n':
run = False
print("\nGoodbye.")
elif continue_calc == 'new':
calculator()
else:
print("Invalid response.")
run = False
print("\nGoodbye.")
calculator()