Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Currency_Converter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Currency Converter
A python script used to convert the currency of one country to that of another country.

## Modules Used
- requests

## How to Use
1. Install necessary requirements using
```bash
pip install -r requirements.txt
```
2. We are using fixer.io API for live conversion rates. Get your access key from [here](https://fixer.io/)
3. Replace **API_KEY** with your own API Key.
4. Input the countries you want to convert respectively and amount to be converted.
35 changes: 35 additions & 0 deletions Currency_Converter/currency_converter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Currency Converter

# Import necessary modules
import requests


class Currency_Converter:
rate = {}

def __init__(self, url):
data = requests.get(url).json()
# Extracting rate from json
self.rate = data["rates"]

# Conversion
def convert(self, from_country, to_country, amount):
initial = amount
if from_country != 'EUR':
amount = amount / self.rates[from_country]

# Precision to 2 decimal places
amount = round(amount * self.rate[to_country], 2)
print(f'{initial} {from_country} = {amount} {to_country}')


# Driver Code
if __name__ == "__main__":
# Replace API_KEY with your own API key from fixer.io
url = 'http://data.fixer.io/api/latest?access_key=API_KEY'
cc = Currency_Converter(url)
from_country = input("From: ")
to_country = input("To: ")
amount = int(input("Amount: "))

cc.convert(from_country, to_country, amount)
1 change: 1 addition & 0 deletions Currency_Converter/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requests