forked from Google-Developer-Student-Club-CCOEW/Competitive-Programming-2023-GDSC-CUMMINS-X-GDSC-MMCOE
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create Tower of Hanoi Google-Developer-Student-Club-CCOEW#140
- Loading branch information
1 parent
5b8a315
commit 7f6eb93
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!") |