Round to 2 decimal places for currency precision
return round(amount * self.rates[to_currency], 2)
Example usage
if __name__ == __main__:
Example exchange rates (as of a hypothetical date)
exchange_rates = {
'USD': 1.0,
'EUR': 0.85,
'GBP': 0.75,
'JPY': 110.0
}
converter = CurrencyConverter(exchange_rates)
amount = float(input(Enter the amount: ))
from_currency = input(Enter the currency you are converting from (e.g., USD): ).upper()
to_currency = input(Enter the currency you are converting to (e.g., EUR): ).upper()
converted_amount = converter.convert(amount, from_currency, to_currency)
print(f{amount} {from_currency} is equal to {converted_amount} {to_currency})