def calculate(num1, operator, num2):
    if operator == '+': 
        return num1 + num2 # This function adds two numbers
    elif operator == '-':
        return num1 - num2 # This function subtracts two numbers
    elif operator == '*':
        return num1 * num2 # This function multiplies two numbers
    elif operator == '/':
        if num2 == 0:
            return "Error: Division by zero not possible!!"
        else:
            return num1 / num2 # This function divides two numbers
    else:
        return "Error: Invalid operator!"     # check if operator is one of the four options
    
print("DEAR USER, WELCOME TO MY CALCULATOR.") #GREETINGS USERS
print("IN A FEW STEPS YOU CAN CALCULATE ANY THING.")

while True:
    try:
        num1 = float(input("1st: Enter the first number: "))     # take input from the user
        operator = input("2nd: Enter the operator (+, -, *, /): ")
        num2 = float(input("3rd: Enter the second number: "))

        result = calculate(num1, operator, num2)
        print("Result:", result)
    except ValueError:
        print("Error: Invalid input! Please enter a valid number.")
    except Exception as e:
        print("An error occurred:", e)
        
    choice = input("Do you want to perform another calculation? (yes/no): ").lower()  # check if user wants another calculation
    if choice != 'yes':  # it means break the while loop if answer is no
        break