Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Objectives
- You're in the bank. Think about how much and what kind of currency you have.
- Take the currency code, the amount of money the user has, and the currency code that the user wants to receive as the user input.
- Retrieve the data from FloatRates as in the previous exercises.
- Save the exchange rates for USD and EUR.
- Read the currency to exchange for and the amount of money.
- Take a look at the cache. Maybe you already have what you need?
- If you have the currency in your cache, calculate the amount.
- If not, get it from the site, and calculate the amount.
- Save all the information to your cache.
- Print the results.
- Repeat steps 4-9 until there is no currency left to process.
- '''
- import requests
- import json
- # write your code here!
- # print('Meet a conicoin!')
- # print('Please, enter the number of conicoins you have:')
- #num = float(input())
- # print('Please, enter the exchange rate:')
- # rate = float(input())
- # print(f'The total amount of dollars: {num * rate}')
- # dollar = num * 100
- # print(f'I have {num} conicoins.')
- # print(f'{num} conicoins cost {num * 100} dollars')
- # print('I am rich! Yippee!')
- '''
- switcher = {
- 'RUB': 2.98,
- 'ARS': 0.82,
- 'HNL': 0.17,
- 'AUD': 1.9622,
- 'MAD': 0.208
- }
- li = [print(f'I will get {switcher[x] * num} {x} from the sale of {num} conicoins.') for x in switcher]
- '''
- choice = input().lower()
- if choice == '':
- exit()
- r = requests.get(f'http://www.floatrates.com/daily/{choice}.json')
- _dict = json.loads(r.text)
- # print(_dict)
- # print(_dict['usd'])
- # print(_dict['eur'])
- cache_dict = {}
- if choice == 'usd':
- cache_dict['eur'] = _dict['eur']
- elif choice == 'eur':
- cache_dict['usd'] = _dict['usd']
- else:
- cache_dict = {'usd': _dict['usd'], 'eur': _dict['eur']}
- # print(cache_dict)
- # print(_dict['usd'])
- # print(_dict['eur'])
- while True:
- goal_currency = input().lower()
- if goal_currency == '':
- break
- money = input()
- if money == '':
- break
- else:
- money = float(money)
- print('Checking the cache...')
- if goal_currency in cache_dict:
- print('Oh! It is in the cache!')
- rate = cache_dict[goal_currency]['rate']
- print(f'You received {round(rate * money, 2)} {goal_currency.upper()}.')
- else:
- print('Sorry, but it is not in the cache!')
- cache_dict[goal_currency] = _dict[goal_currency]
- rate = cache_dict[goal_currency]['rate']
- print(f'You received {round(rate * money, 2)} {goal_currency.upper()}.')
- '''rates = {}
- if source_code != 'usd':
- rates['usd'] = data['usd']['rate']
- if source_code != 'eur':
- rates['eur'] = data['eur']['rate']
- '''
Add Comment
Please, Sign In to add comment