forked from Rishi098/Python_Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalculator2.0.py
62 lines (50 loc) · 1.32 KB
/
Calculator2.0.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
60
61
62
logo = """
_____________________
| _________________ |
| | Python 0. | |
| |_________________| |
| ___ ___ ___ ___ |
| | 7 | 8 | 9 | | + | |
| |___|___|___| |___| |
| | 4 | 5 | 6 | | - | |
| |___|___|___| |___| |
| | 1 | 2 | 3 | | x | |
| |___|___|___| |___| |
| | . | 0 | = | | / | |
| |___|___|___| |___| |
|_____________________|
"""
def add(n1,n2):
return n1 + n2
def sub(n1,n2):
return n1 - n2
def multiply(n1,n2):
return n1 * n2
def divide(n1,n2):
return n1 / n2
def calculator():
print(logo)
num1 = float(input("Whats the first number "))
should_continue = True
while should_continue :
operations = {"+" : add,
"-" : sub,
"*" : multiply,
"/" : divide}
for symbol in operations:
print(symbol)
opr = input("Pick an Operator ")
num2 = float(input("Whats the next number "))
result = operations[opr](num1,num2)
print(f"{num1} {opr} {num2} = {result}")
while True:
choice = input(f"type 'y' to continue with {result} or type 'n' to start new ").lower()
if choice == "y":
num1 = result
break
elif choice == "n":
should_continue = False
calculator()
else :
print("Typo Mistake! ")
calculator()