d     return x + y

def subtract(x, y):
    return x - y

def multiply(x, y):
    return x * y

def divide(x, y):
    if y == 0:
        return "Error! Division by zero."
    else:
        return x / y

def calculator():
    while True:
        try:
            num1 = float(input("Enter the first number: "))
            operator = input("Enter an operator (+, -, *, /): ")
            num2 = float(input("Enter the second number: "))

            if operator == '+':
                print("Result:", add(num1, num2))
            elif operator == '-':
                print("Result:", subtract(num1, num2))
            elif operator == '*':
                print("Result:", multiply(num1, num2))
            elif operator == '/':
                print("Result:", divide(num1, num2))
            else:
                print("Invalid operator!")

            choice = input("Do you want to perform another calculation? (yes/no): ")
            if choice.lower() != 'yes':
                print("Goodbye!")
                break
        except ValueError:
            print("Invalid input! Please enter valid numbers.")
        except Exception as e:
            print("An error occurred:", 
