-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculator.py
More file actions
60 lines (44 loc) · 1.31 KB
/
Copy pathCalculator.py
File metadata and controls
60 lines (44 loc) · 1.31 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
# first of all we will add all the 4 methods
#add method
def add(n1, n2):
return n1 + n2
#subtract method
def subtract(n1, n2):
return n1 - n2
#multiply method
def multiply(n1, n2):
return n1 * n2
#divide method
def divide(n1, n2):
return n1 / n2
"""
we will create a dictionary where we will be storing the symbols which will do the functions
"""
sign_dictionary = {
"+" : add,
"-" : subtract,
"*" : multiply,
"/" : divide
}
#print(sign_dictionary["*"](4, 8))
def calculator():
# now we will ask the user for the first number
n1 = int(input("Enter the first number:"))
should_continue = True
while should_continue:
sign = input("Enter the operation you want to perform:")
n2 = int(input("Enter the second number:"))
print((sign_dictionary[sign](n1, n2)))
# we will store incase we need that later
ans = (sign_dictionary[sign](n1, n2))
next_step = input("Do you want to perform another operation?(yes/no): ")
if next_step.lower() == "yes":
n1 = ans
elif next_step.lower() == "no":
should_continue = False
calculator()
else:
should_continue = False
print("Thank you for using this calculator")
#my dumbass did not call the calculator
calculator()