Skip to content

Commit aa255ac

Browse files
committed
Adding currency convertor app
1 parent 13c73f6 commit aa255ac

File tree

7 files changed

+64
-0
lines changed

7 files changed

+64
-0
lines changed

09_Currency_convertor/.idea/.gitignore

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

09_Currency_convertor/.idea/09_Currency_convertor.iml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

09_Currency_convertor/.idea/inspectionProfiles/profiles_settings.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

09_Currency_convertor/.idea/misc.xml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

09_Currency_convertor/.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

09_Currency_convertor/.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import requests
2+
3+
# Currency available in the API
4+
print("Currencies available: ", ['CAD', 'HKD', 'ISK', 'PHP', 'DKK', 'HUF', 'CZK', 'AUD', 'RON', 'SEK', 'IDR', 'INR',
5+
'BRL', 'RUB', 'HRK', 'JPY', 'THB', 'CHF', 'SGD', 'PLN', 'BGN', 'TRY', 'CNY', 'NOK',
6+
'NZD', 'ZAR', 'USD', 'MXN', 'ILS', 'GBP', 'KRW', 'MYR'])
7+
8+
# Gathering input parameters from the user
9+
date = input("Please enter the date (in the format 'yyyy-mm-dd' or 'latest'): ")
10+
base = input("Convert from (currency): ")
11+
curr = input("Convert to (currency): ")
12+
quan = float(input(f"How much {base} do you want to convert: "))
13+
14+
# Constructing the URL based on the user parameters and sending a request to the server
15+
base_url = "https://api.exchangeratesapi.io"
16+
url = f"{base_url}/{date}?base={base}&symbols={curr}"
17+
response = requests.get(url)
18+
19+
# Displaying the error message, if something went wrong
20+
if not response.ok:
21+
print(f"\nError {response.status_code}:")
22+
print(response.json()['error'])
23+
24+
else:
25+
data = response.json()
26+
rate = data['rates'][curr]
27+
28+
result = quan * rate
29+
30+
print(f"\n{quan} {base} is equal to {result:.2f} {curr}, based upon exchange rates on {data['date']}")

0 commit comments

Comments
 (0)