-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcal.py
More file actions
37 lines (29 loc) · 965 Bytes
/
cal.py
File metadata and controls
37 lines (29 loc) · 965 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
27
28
29
30
31
32
33
34
35
36
37
# Simple Calculator
# Prompt the user to enter two numbers
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
# Show operation choices
print("\nChoose operation:")
print("1. Addition (+)")
print("2. Subtraction (-)")
print("3. Multiplication (*)")
print("4. Division (/)")
choice = input("Enter your choice (1/2/3/4): ")
# Perform calculation
if choice == '1':
result = num1 + num2
print(f"Result: {num1} + {num2} = {result}")
elif choice == '2':
result = num1 - num2
print(f"Result: {num1} - {num2} = {result}")
elif choice == '3':
result = num1 * num2
print(f"Result: {num1} * {num2} = {result}")
elif choice == '4':
if num2 != 0:
result = num1 / num2
print(f"Result: {num1} / {num2} = {result}")
else:
print("Error: Division by zero is not allowed!")
else:
print("Invalid choice! Please select 1, 2, 3, or 4.")