Advertisement
coolichikem

Untitled

Dec 11th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.56 KB | None | 0 0
  1. from forex_python.converter import CurrencyRates
  2. from forex_python.converter import CurrencyCodes
  3. from datetime import datetime
  4.  
  5. cr = CurrencyRates()
  6. cd = CurrencyCodes()
  7.  
  8.  
  9. def converter(currency1, currency2, money):
  10.     return cr.convert(currency1, currency2, money)
  11.  
  12.  
  13. def converter_with_data(currency1, currency2, money, date_obj):
  14.     return cr.convert(currency1, currency2, money, date_obj)
  15.  
  16.  
  17. def get_history(history):
  18.     for line in history:
  19.         print(line)
  20.  
  21.  
  22. while True:
  23.     print('Какую валюту Вы хотели бы поменять?')
  24.     currency_from = str(input())
  25.     while currency_from not in cr.get_rates('USD'):
  26.         print('Кажется, Вы ошиблись. Введите валюту еще раз:')
  27.         currency_from = str(input())
  28.  
  29.     print('Какую валюту Вы хотели бы получить?')
  30.     currency_to = str(input())
  31.     while currency_to not in cr.get_rates('USD'):
  32.         print('Кажется, Вы ошиблись. Введите валюту еще раз:')
  33.         currency_to = str(input())
  34.  
  35.     print('Сколько денег (' + cd.get_currency_name(currency_from) + ') Вы хотите поменять?')
  36.     amount_of_money = float(input())
  37.  
  38.     print('Хотели бы Вы обменять валюту в ретроспективе?')
  39.     print('Введите "да" или "нет":')
  40.  
  41.     yes_or_no = str(input())
  42.     while yes_or_no != "да" and yes_or_no != "нет":
  43.         print('Кажется, Вы ошиблись. Введите ответ еще раз:')
  44.         yes_or_no = str(input())
  45.  
  46.     if yes_or_no == "нет":
  47.         print('Вы получите:')
  48.         final_sum = converter(currency_from, currency_to, amount_of_money), cd.get_symbol(currency_to)
  49.         print(final_sum)
  50.  
  51.     elif yes_or_no == "да":
  52.         print('Введите дату:')
  53.         print('Год:')
  54.         year = int(input())
  55.         print('Месяц:')
  56.         month = int(input())
  57.         print('День:')
  58.         day = int(input())
  59.         date = datetime(year, month, day)
  60.         print('Вы получите:')
  61.         final_sum = converter_with_data(currency_from, currency_to, amount_of_money, date), cd.get_symbol(currency_to)
  62.         print(final_sum)
  63.  
  64.     history = []
  65.     history += ["Конвертировал " + str(amount_of_money) + cd.get_symbol(currency_from) + " в " + str(cd.get_symbol(currency_to))
  66.                 + " по курсу " + str(cr.get_rate(currency_from, currency_to)) + " и получил " + str(final_sum)]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement