-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
57 lines (38 loc) · 1.09 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
53
54
55
56
57
from art import logo
import os
def clear(): return os.system('clear')
def add(n1, n2):
return n1 + n2
def substract(n1, n2):
return n1 - n2
def multiply(n1, n2):
return n1 * n2
def devide(n1, n2):
return n1 / n2
operations = {
"+": add,
"-": substract,
"*": multiply,
"/": devide,
}
def calculator():
print(logo)
continue_calculating = True
num1 = float(input("What's the first number? "))
for symbol in operations:
print(symbol)
while continue_calculating:
operation_symbol = input("Pick an operation: ")
num2 = float(input("What's the next number? "))
calculation_function = operations[operation_symbol]
answer = calculation_function(num1, num2)
print(f"{num1} {operation_symbol} {num2} = {answer}")
should_continue = input(
f"'y' to continue calculating with {answer}, 'n' to start new calculation: ")
if should_continue == "n":
continue_calculating = False
clear()
calculator()
else:
num1 = answer
calculator()