#!/usr/bin/env python3 import sys import requests def convert_currency(amount, from_currency, to_currency): url = f"https://api.frankfurter.app/latest?amount={amount}&from={from_currency}&to={to_currency}" response = requests.get(url) if response.status_code == 200: data = response.json() converted_amount = data['rates'][to_currency] print(f"{amount} {from_currency} = {converted_amount} {to_currency}") else: print("Error: Unable to fetch exchange rates.") def main(): if len(sys.argv) != 4: print("Usage: currency_converter.py ") print("Example: currency_converter.py 100 CAD USD") sys.exit(1) amount = float(sys.argv[3]) from_currency = sys.argv[1].upper() to_currency = sys.argv[2].upper() convert_currency(amount, from_currency, to_currency) if __name__ == "__main__": main()