-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
61 lines (41 loc) · 1.89 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from online import get_currencies
# 1. Приветствие
# 2. Мануал – как пользоваться программой и какие валюты доступны
# 3. Ввести исходную валюту
# 4. Ввести в какую валюту перевести
# 5. Количество валюты
# 7. Вывод результата
online_response = get_currencies()
def convert(amount, from_ticker, to_ticker, currencies):
from_currency = currencies.get(from_ticker)
to_currency = currencies.get(to_ticker)
coefficient = to_currency / from_currency
return round(amount * coefficient, 2)
def input_currency(input_message, currencies):
ticker = input(f"{input_message}: ").strip()
currency = currencies.get(ticker, None)
if currency is None:
print(f'Ошибка при поиске валюты: {ticker}')
exit()
return ticker
current_currencies = {
'RUB': 97.4545572753,
'EUR': 0.9487101161,
'USD': 1,
}
print("Привет, это программа Конвертер Валют!")
print("""
Для работы с программой требуется:
- выбрать исходную валюту
- выбрать в какую валюту следует перевести
- ввести количество исходной валюты
Доступные валюты:
""")
for currency in current_currencies:
print(f'- {currency}')
from_ticker = input_currency("Введите исходную валюту", current_currencies)
to_ticker = input_currency("Введите в какую валюту следует перевести", current_currencies)
amount_input = input("Введите количество валюты: ")
amount = int(amount_input)
result = convert(amount, from_ticker, to_ticker, current_currencies)
print(f'Результат: {amount} {from_ticker} = {result} {to_ticker}')