└── cconverter.py /cconverter.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import json 3 | 4 | 5 | def print_message(amount, rate, code): 6 | print(f'You received {round(amount * rate, 2)} {code.upper()}.') 7 | 8 | 9 | def main(): 10 | my_currency_code = input().lower() 11 | r = requests.get(f'http://www.floatrates.com/daily/{my_currency_code}.json') 12 | if my_currency_code.lower() != 'usd': 13 | exchange_cache = {'usd': json.loads(r.content)['usd']['rate'], 14 | 'eur': json.loads(r.content)['eur']['rate']} 15 | else: 16 | exchange_cache = {'usd': 1, 17 | 'eur': json.loads(r.content)['eur']['rate']} 18 | 19 | while True: 20 | receive_currency_code = input().lower() 21 | if not receive_currency_code: 22 | break 23 | my_currency_amount = float(input()) 24 | print(f'Checking the cache...') 25 | if receive_currency_code in exchange_cache: 26 | print(f'Oh! It is in the cache!') 27 | print_message(my_currency_amount, exchange_cache[receive_currency_code], receive_currency_code) 28 | else: 29 | print(f'Sorry, but it is not in the cache!') 30 | exchange_cache[receive_currency_code] = json.loads(r.content)[receive_currency_code]["rate"] 31 | print_message(my_currency_amount, exchange_cache[receive_currency_code], receive_currency_code) 32 | 33 | 34 | if __name__ == '__main__': 35 | main() 36 | --------------------------------------------------------------------------------