Skip to content

Commit 823876e

Browse files
authored
Add files via upload
1 parent 4cba373 commit 823876e

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

currency_exchange.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import requests
2+
3+
def get_exchange_rates(base, targets):
4+
url = f"https://api.frankfurter.app/latest?from={base}&to={','.join(targets)}"
5+
response = requests.get(url)
6+
data = response.json()
7+
return data.get("rates", {})
8+
9+
# List of supported currencies
10+
currencies = ["INR", "USD", "GBP", "EUR", "SAR"]
11+
12+
print("Available currencies:", ", ".join(currencies))
13+
base_currency = input("Choose base currency (e.g., USD): ").upper()
14+
15+
if base_currency not in currencies:
16+
print("Invalid currency! Please choose from the list.")
17+
else:
18+
try:
19+
amount = float(input(f"Enter amount in {base_currency}: "))
20+
except ValueError:
21+
print("Invalid amount entered!")
22+
exit()
23+
24+
targets = [c for c in currencies if c != base_currency]
25+
rates = get_exchange_rates(base_currency, targets)
26+
27+
print(f"\nExchange Rates for {amount} {base_currency}:\n")
28+
for target, rate in rates.items():
29+
converted = amount * rate
30+
print(f"{amount} {base_currency} = {converted:.2f} {target}")

0 commit comments

Comments
 (0)