Skip to content

Commit b15c161

Browse files
committed
feat: Added currency converter using fixer[.]io
1 parent 6a9e801 commit b15c161

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

Currency Converter/main.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import requests
2+
3+
class Currency_convertor:
4+
rates = {}
5+
def __init__(self, url):
6+
data = requests.get(url).json()
7+
self.rates = data["rates"]
8+
9+
def convert(self, from_currency, to_currency, amount):
10+
initial_amount = amount
11+
if from_currency != 'EUR' :
12+
amount = amount / self.rates[from_currency]
13+
14+
amount = round(amount * self.rates[to_currency], 2)
15+
print('{} {} = {} {}'.format(initial_amount, from_currency, amount, to_currency))
16+
17+
if __name__ == "__main__":
18+
url = str.__add__('http://data.fixer.io/api/latest?access_key=', YOUR_ACCESS_KEY)
19+
c = Currency_convertor(url)
20+
amount = int(input("Amount: "))
21+
from_country = input("From Country: ")
22+
to_country = input("TO Country: ")
23+
24+
c.convert(from_country, to_country, amount)
16 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)