-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculator(Project-6).py
More file actions
69 lines (37 loc) · 1.22 KB
/
Calculator(Project-6).py
File metadata and controls
69 lines (37 loc) · 1.22 KB
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
63
64
65
66
67
68
69
import os
def add(a,b):
return a+b
def subtract(a,b):
return a-b
def multiply(a,b):
return a*b
def divide(a,b):
return a/b
operation_dict={
"+":add,
"-":subtract,
"*":multiply,
"/":divide
}
def calculator():
number1=float(input("Enter First Number:"))
for symbol in operation_dict:
print(symbol)
continue_flag=True
while continue_flag:
op_symbol=input("Pick an Operation:")
number2=float(input("Enter Second Number:"))
calculator_function=operation_dict[op_symbol] #add
output=calculator_function(number1,number2)
print(f"{number1} {op_symbol} {number2} = {output}")
should_continue=input(f"Enter 'Y' to continue calculation with {output} or 'N' to start a new calculator or 'x' to exit.").lower()
if should_continue == 'y':
number1=output
elif should_continue == 'n':
continue_flag=False
os.system('cls')
calculator()
else:
continue_flag=False
print("Thanks For Using Our Program, Wish You Best Of Luck ✌️.")
calculator()