From 7f6eb93bf2558726072528dc689d62ff8e826c1a Mon Sep 17 00:00:00 2001 From: vaishnavim141003 <111603962+vaishnavim141003@users.noreply.github.com> Date: Tue, 31 Oct 2023 12:36:05 +0530 Subject: [PATCH] Create Tower of Hanoi #140 --- Tower of Hanoi #140 | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Tower of Hanoi #140 diff --git a/Tower of Hanoi #140 b/Tower of Hanoi #140 new file mode 100644 index 0000000..aef313d --- /dev/null +++ b/Tower of Hanoi #140 @@ -0,0 +1,41 @@ +import requests + +# Function to fetch exchange rates from the 'fixer.io' API +def get_exchange_rates(base_currency): + url = f"https://api.fixer.io/latest?base={base_currency}" + response = requests.get(url) + data = response.json() + return data['rates'] + +# Function to perform currency conversion +def convert_currency(amount, from_currency, to_currency): + rates = get_exchange_rates(from_currency) + if to_currency in rates: + conversion_rate = rates[to_currency] + converted_amount = amount * conversion_rate + return converted_amount, conversion_rate + else: + return None + +# Main program +if __name__ == "__main__": + print("Currency Converter App") + + while True: + base_currency = input("Enter the base currency (e.g., USD): ") + amount = float(input("Enter the amount: ")) + target_currency = input("Enter the target currency (e.g., EUR): ") + + result = convert_currency(amount, base_currency, target_currency) + if result: + converted_amount, conversion_rate = result + print(f"{amount} {base_currency} is equal to {converted_amount} {target_currency}") + print(f"Conversion rate: 1 {base_currency} = {conversion_rate} {target_currency}") + else: + print(f"Conversion from {base_currency} to {target_currency} is not supported.") + + another_conversion = input("Do another conversion? (yes/no): ").lower() + if another_conversion != "yes": + break + + print("Goodbye!")