-
Notifications
You must be signed in to change notification settings - Fork 0
/
basic
49 lines (40 loc) · 1.16 KB
/
basic
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
def add(num1, num2):
return num1 + num2
def subtract(num1, num2):
return num1 - num2
def multiply(num1, num2):
return num1 * num2
def divide(num1, num2):
if num2 != 0:
return num1 / num2
else:
return "Error: Cannot divide by zero."
def calculator():
print("Simple Calculator")
print("1. Add")
print("2. Subtract")
print("3. Multiply")
print("4. Divide")
print("5. Exit")
while True:
choice = input("Enter your choice (1-5): ")
if choice == "5":
print("Goodbye!")
break
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
if choice == "1":
result = add(num1, num2)
print("Result:", result)
elif choice == "2":
result = subtract(num1, num2)
print("Result:", result)
elif choice == "3":
result = multiply(num1, num2)
print("Result:", result)
elif choice == "4":
result = divide(num1, num2)
print("Result:", result)
else:
print("Invalid choice. Try again.")
calculator()