-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
26 lines (22 loc) · 768 Bytes
/
Copy pathmain.py
File metadata and controls
26 lines (22 loc) · 768 Bytes
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
# Basic Calculator
def calculator():
print("Select operation:")
print("1. Add\n2. Subtract\n3. Multiply\n4. Divide")
choice = input("Enter choice (1/2/3/4): ")
if choice in ['1', '2', '3', '4']:
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
if choice == '1':
print(f"Result: {num1 + num2}")
elif choice == '2':
print(f"Result: {num1 - num2}")
elif choice == '3':
print(f"Result: {num1 * num2}")
elif choice == '4':
if num2 != 0:
print(f"Result: {num1 / num2}")
else:
print("Division by zero is not allowed.")
else:
print("Invalid choice.")
calculator()