def convert_currency(amount, from_currency, to_currency):
    # Conversion Rates as of May 6th, 2023
    usd_rates = {'USD': 1, 'SAR': 3.75, 'AED': 3.67}
    sar_rates = {'USD': 0.26, 'SAR': 1, 'AED': 0.97}
    aed_rates = {'USD': 0.27, 'SAR': 1.02, 'AED': 1}

    # Convert prefix to currency code
    currency_codes = {'1': 'USD', '2': 'SAR', '3': 'AED'}
    from_currency_code = currency_codes.get(from_currency)
    to_currency_code = currency_codes.get(to_currency)

    # Check if the currencies are the same
    if from_currency_code == to_currency_code:
        return amount, from_currency_code, to_currency_code

    # Convert amount to USD
    usd_amount = amount / usd_rates[from_currency_code]

    # Convert from USD to desired currency
    converted_amount = usd_amount * usd_rates[to_currency_code]

    return round(converted_amount, 2), from_currency_code, to_currency_code

# Main program loop
while True:
    # Get user input
    while True:
        try:
            amount = float(input("Enter amount to be converted: "))
            break
        except ValueError:
            print("Invalid input. Please enter a valid number.")

    from_prefix = input("Enter the number of the currency to convert from ('1' for USD|'2' for SAR|'3' for AED): ")
    to_prefix = input("Enter the number of the currency to convert to ('1' for USD|'2' for SAR|'3' for AED): ")

    # Check if input is valid
    if from_prefix not in ('1', '2', '3') or to_prefix not in ('1', '2', '3'):
        print("Invalid input. Please try again.")
        continue

    # Convert currency and print result
    converted_amount, from_currency, to_currency = convert_currency(amount, from_prefix, to_prefix)
    if from_prefix == to_prefix:
        print(f"{converted_amount:.2f}")
    else:
        print(f"{amount:.2f} {from_currency} = {converted_amount:.2f} {to_currency}")

    # Ask user if they want to convert again
    choice = input("Do you want to convert again? (Y/N): ").upper()
    if choice != 'Y':
        break

print("Thank you for using the currency converter!😊")
print("Powered by Yazan Abdulwahab")