Define a class ExchangePoint which should be responsible for converting between…
- User
Define a class ExchangePoint which should be responsible for converting between different currencies; GBP, EUR and USD. The class should accept in the init method the conversion rates and should also have three functions; get gbp, get eur, and get usd. All three functions should accept three arguments (‘gbp’, ‘eur’, ‘usd’), which correspond to the amount from each currency we wish to include in the conversion.
- Assistant
Here's an implementation of the
ExchangePointclass:class ExchangePoint: def __init__(self, gbp_rate, eur_rate, usd_rate): self.gbp_rate = gbp_rate self.eur_rate = eur_rate self.usd_rate = usd_rate def get_gbp(self, gbp, eur, usd): return gbp + (eur * self.eur_rate / self.gbp_rate) + (usd * self.usd_rate / self.gbp_rate) def get_eur(self, gbp, eur, usd): return (gbp * self.gbp_rate / self.eur_rate) + eur + (usd * self.usd_rate / self.eur_rate) def get_usd(self, gbp, eur, usd): return (gbp * self.gbp_rate / self.usd_rate) + (eur * self.eur_rate / self.usd_rate) + usd # Example usage: exchange = ExchangePoint(0.87, 1.21, 1.0) gbp_amount = 100 eur_amount = 120 usd_amount = 150 converted_gbp = exchange.get_gbp(gbp_amount, eur_amount, usd_amount) print(f"GBP: {gbp_amount} => {converted_gbp}") converted_eur = exchange.get_eur(gbp_amount, eur_amount, usd_amount) print(f"EUR: {eur_amount} => {converted_eur}") converted_usd = exchange.get_usd(gbp_amount, eur_amount, usd_amount) print(f"USD: {usd_amount} => {converted_usd}")