-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalculator.py
54 lines (43 loc) · 1.44 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
def add(x, y):
return x + y
def subtract(x, y):
return x - y
def multiply(x, y):
return x * y
def divide(x, y):
if y != 0:
return x / y
else:
return ("Cannot divide by zero.")
def main():
print("---------------------------------------------")
print("\nWhat operation would you like to perform?")
print("1. Addition")
print("2. Subtraction")
print("3. Multiplication")
print("4. Division")
try:
operation =int(input("\nEnter your choice: "))
if(operation<5):
num1 = int(input("\nEnter the first number: "))
num2 = int(input("Enter the second number: "))
print()
if operation == 1:
print("•Result:",num1, "+", num2, "=", add(num1, num2))
elif operation == 2:
print("•Result:",num1, "-", num2, "=", subtract(num1, num2))
elif operation == 3:
print("•Result:",num1, "*", num2, "=", multiply(num1, num2))
elif operation == 4:
print("•Result:",num1, "/", num2, "=", divide(num1, num2))
else:
print("!Invalid operation.\n")
else:
print("Choice must be between 1 to 4\n")
main()
except:
print("Please enter numeric values only...!\n")
main()
while True:
if __name__ == "__main__":
main()