Skip to content

Commit b7b8125

Browse files
committed
Added Currency Converter script
1 parent 57bf673 commit b7b8125

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

Currency Converter/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<div align="center">
2+
3+
# Currency Converter
4+
5+
</div>
6+
7+
### Description:
8+
This Python script converts an amount from one currency to another using real-time exchange rates fetched from an API.
9+
10+
### How to Use:
11+
1. Run the script in a Python environment.
12+
2. Enter the amount to convert when prompted.
13+
3. Enter the source currency (e.g., USD, EUR) when prompted.
14+
4. Enter the target currency (e.g., USD, EUR) when prompted.
15+
5. The script will fetch the real-time exchange rates and perform the currency conversion, displaying the result.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import requests
2+
3+
4+
def convert_currency(amount, from_currency, to_currency):
5+
api_key = 'YOUR_API_KEY'
6+
url = f'https://api.exchangerate-api.com/v4/latest/{from_currency}'
7+
response = requests.get(url)
8+
data = response.json()
9+
exchange_rate = data['rates'][to_currency]
10+
converted_amount = amount * exchange_rate
11+
return converted_amount
12+
13+
14+
def main():
15+
amount = float(input("Enter the amount to convert: "))
16+
from_currency = input("Enter the source currency: ").upper()
17+
to_currency = input("Enter the target currency: ").upper()
18+
converted_amount = convert_currency(amount, from_currency, to_currency)
19+
print(f"{amount} {from_currency} is equal to {converted_amount} {to_currency}")
20+
21+
22+
if __name__ == "__main__":
23+
main()

0 commit comments

Comments
 (0)