Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
vaishnavim141003 authored Oct 31, 2023
1 parent 5b8a315 commit 7f6eb93
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions Tower of Hanoi #140
Original file line number Diff line number Diff line change
@@ -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!")

0 comments on commit 7f6eb93

Please sign in to comment.