-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathcalculator.py
56 lines (53 loc) · 2.56 KB
/
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
from replit import clear
#For Clearing outputs
logo = """
_____________________
| _________________ |
| | Pythonista 0. | | .----------------. .----------------. .----------------. .----------------.
| |_________________| | | .--------------. || .--------------. || .--------------. || .--------------. |
| ___ ___ ___ ___ | | | ______ | || | __ | || | _____ | || | ______ | |
| | 7 | 8 | 9 | | + | | | | .' ___ | | || | / \ | || | |_ _| | || | .' ___ | | |
| |___|___|___| |___| | | | / .' \_| | || | / /\ \ | || | | | | || | / .' \_| | |
| | 4 | 5 | 6 | | - | | | | | | | || | / ____ \ | || | | | _ | || | | | | |
| |___|___|___| |___| | | | \ `.___.'\ | || | _/ / \ \_ | || | _| |__/ | | || | \ `.___.'\ | |
| | 1 | 2 | 3 | | x | | | | `._____.' | || ||____| |____|| || | |________| | || | `._____.' | |
| |___|___|___| |___| | | | | || | | || | | || | | |
| | . | 0 | = | | / | | | '--------------' || '--------------' || '--------------' || '--------------' |
| |___|___|___| |___| | '----------------' '----------------' '----------------' '----------------'
|_____________________|
"""
print(logo)
# Calculation part
def calc(a, b, op):
if (op == "+"):
return (a + b)
elif (op == "-"):
return (a - b)
elif (op == "*"):
return (a * b)
elif (op == "/"):
return (a / b)
# Main Program
flag = 0
should_continue = True
# While loop for Repeating Calculation
while (should_continue):
if (flag == 0):
number_1 = float(input("What's the first number : "))
flag=0 #almost like backtracking but just to omit re-input
print("+\n-\n*\n/\n") #operators print
op = input("Pick an operator from above : ")
number_2 = float(input("What's the next number : "))
print(f"{number_1} {op} {number_2} : {calc(number_1,number_2,op)}")
result = input(
f"type 'y' to continue calculating with {calc(number_1,number_2,op)}, or type 'n' to start a new calculation, or type 'exit' for exit calculator "
)
if (result == "exit"): #For exit from the Program
should_continue = False
print("Goodbye")
break
elif (result == "y"): #For calculating with same Inputs
flag = 1
number_1 = int(calc(number_1, number_2, op))
else: #For starting the program from first step
clear()