# define a function to perform calculations def calculator(num1, num2, operator): if operator == '+': result = num1 + num2 elif operator == '-': result = num1 - num2 elif operator == '*': result = num1 * num2 elif operator == '/': if num2 == 0: result = "Error: Cannot divide by zero" else: result = num1 / num2 else: result = "Error: Invalid operator" return result # ask the user for input num1 = float(input("Enter the first number: ")) num2 = float(input("Enter the second number: ")) operator = input("Enter the operator (+, -, *, /): ") # call the calculator function and print the result result = calculator(num1, num2, operator) print("Result: ", result)