input: Write a python function to convert currency using a given exchange rate.
  assert convert_currency("USD", "EUR", 100, {"USD": 1.0, "EUR": 0.85}) == 85.0
  assert convert_currency("EUR", "USD", 100, {"USD": 1.18, "EUR": 1.0}) == 118.0
  assert convert_currency("GBP", "JPY", 50, {"GBP": 1.0, "JPY": 150.0}) == 7500.0
output: def convert_currency(from_currency, to_currency, amount, exchange_rates):
      if from_currency not in exchange_rates or to_currency not in exchange_rates:
          raise ValueError("Invalid currency code")
      rate = exchange_rates[to_currency] / exchange_rates[from_currency]
      return amount * rate