import requests import json def base_input(): """Getting action input.""" base = input('\nConvert from: ').upper() return base def to_input(): """Getting action input.""" to = input('Convert to: ').upper() return to def currency_abbreviations(): currency = '(USD, EUR, GBP, PLN)' return currency def exchange_connector(): print('\nAvailable currencies: ') print('-' * 60) currencies = currency_abbreviations() print(currencies) base = base_input() if base in currencies: url = (f'https://api.exchangeratesapi.io/latest?base={base}') response = requests.get(url) data = response.text parsed = json.loads(data) rates = parsed['rates'] exchange_rates(base, rates, parsed) print('dsd') elif base == '0': quit('bye') else: print('There is no such currency in the database.\n') exchange_connector() def exchange_rates(base, rates, parsed): print(f'\nConversion rate per 100 {base}') print('-' * 60) for currency, rate in rates.items(): print(f'{currency} = {round(100 * rate, 4)}') date = parsed['date'] print('\ndate:', date) print('-' * 60) exchange_connector() # ----------------------------------------------------------------------------- """Actual output: CAD = 128.0481 HKD = 775.265 ISK = 12926.6461 PHP = 4810.2312 DKK = 620.5625 HUF = 29757.156 CZK = 2153.5509 GBP = 73.0518 RON = 406.8013 SEK = 844.7634 IDR = 1403675.2065 INR = 7290.9121 BRL = 544.5047 RUB = 7479.9716 HRK = 631.0023 JPY = 10574.9812 THB = 3010.0142 CHF = 90.3363 EUR = 83.4516 MYR = 407.0517 BGN = 163.2146 TRY = 707.277 CNY = 647.0416 NOK = 860.1185 NZD = 139.9983 ZAR = 1497.1793 USD = 100.0 MXN = 2031.9619 SGD = 133.7979 AUD = 131.528 ILS = 329.2665 KRW = 112279.8965 PLN = 375.7239 date: 2021-02-05 ------------------------------------------------------------ Process finished with exit code 0 """ # ------------------------------------------------------------------------------------ """Proper output: USD = 100.0 EUR = 83.4516 GBP = 73.0518 PLN = 375.7239 """