def calculate(num1, num2, operation): if operation == '+': return num1 + num2 elif operation == '-': return num1 - num2 elif operation == '*': return num1 * num2 elif operation == '/': if num2 == 0: return "Error: Division by zero is not allowed." return num1 / num2 else: return "Invalid operation. Please choose from +, -, *, or /."
def main(): # Ask the user for input num1 = float(input("Enter the first number: ")) num2 = float(input("Enter the second number: ")) operation = input("Enter the operation (+, -, *, /): ")
# Perform the calculation
result = calculate(num1, num2, operation)
# Display the result
print(f"{num1} {operation} {num2} = {result}")
if name == "main": main()# python-introduction