#-- https://nemiatools.com --#
import requests # Import HTTP library
url = "https://api.frankfurter.app/latest" # Set API URL
# Get available currencies
response = requests.get(url) # Send GET request
response.raise_for_status() # Check request status
all_currencies = response.json()["rates"] # Get currency rates
all_currencies["EUR"] = 1.0 # Add EUR base currency
print("Currency Names:", ", ".join(sorted(all_currencies)), "\n") # Print currencies
while True: # Repeat program
while True: # Ask input currency
currency_in = input("Enter current currency: ").upper() # Read input currency
if currency_in in all_currencies: # Check currency exists
break # Exit loop
print("Currency not found. Try again.\n") # Show error
while True: # Ask output currency
currency_out = input("Enter final currency: ").upper() # Read output currency
if currency_out in all_currencies: # Check currency exists
break # Exit loop
print("Currency not found. Try again.\n") # Show error
while True: # Ask amount
amount_in = float(
input(f"Enter amount to exchange in {currency_in}: ")
) # Read amount
if amount_in > 0: # Check positive amount
break # Exit loop
print("Invalid amount.\n") # Show error
data = requests.get(url, params={"from": currency_in}).json() # Get exchange data
amount_out = data["rates"][currency_out] * amount_in # Convert amount
print(f"Final amount: {amount_out:.2f} {currency_out}\n") # Print result