# Prompt the user for the first number, the operation, and the second number
num1 = float(input("Enter the first number: "))
operation = input("Enter operation (+, -, *, x, /): ")
num2 = float(input("Enter the second number: "))
# Perform the operation based on the input
if operation == "+":
result = num1 + num2
print(f"{num1} + {num2} = {result}")
elif operation == "-":
result = num1 - num2
print(f"{num1} - {num2} = {result}")
elif operation == "*":
result = num1 * num2
print(f"{num1} * {num2} = {result}")
elif operation == "x":
result = num1 * num2
print(f"{num1} x {num2} = {result}")
elif operation == "/":
if num2 != 0:
result = num1 / num2
print(f"{num1} / {num2} = {result}")
else:
print("Error: Cannot divide by zero.")
else:
print("Invalid operation. Please enter one of +, -, *, x, or /.")
Output
Case 1:
Enter the first number: 5
Enter operation (+, -, *, x, /): +
Enter the second number: 7
5.0 + 7.0 = 12.0
Case 2:
Enter the first number: 10
Enter operation (+, -, *, x, /): x
Enter the second number: 3
10.0 x 3.0 = 30.0
Case 3:
Enter the first number: 8
Enter operation (+, -, *, x, /): /
Enter the second number: 2
8.0 / 2.0 = 4.0