Домашни > Да върнем левчето обратно! > Решения > Решението на Алекс Карабашев

Резултати
6 точки от тестове
0 точки от учител

6 точки общо

10 успешни теста
0 неуспешни теста
Код
Скрий всички коментари

 1def курс_в_лева(exchange_rates):
 2    return {currency: round(1 / rate, 4) for currency, rate in exchange_rates.items()}
 3
 4exchange_rates = {"EUR": 1.9558, "USD": 1.6718, "DKK": 0.2616}
 5print(курс_в_лева(exchange_rates))
 6
 7def валута_към_левчета(*args, **kwargs):
 8    converted_to_lev = {}
 9    for currency, value in args:
10        if not currency in converted_to_lev:
11            converted_to_lev[currency] = 0
12        if currency == "BGN":
13            converted_to_lev[currency] += value
14        else:
15            converted_to_lev[currency] += value / kwargs[currency]
16    return [(currency, round(amount, 4)) for currency, amount in converted_to_lev.items()]
17
18print(валута_към_левчета(
19    ("EUR", 1.5),
20    ("USD", 10),
21    ("DKK", 10),
22    ("EUR", 2.5),
23    EUR=0.5,
24    USD=0.8,
25    DKK=7,
26))
27print(валута_към_левчета(
28    ("BGN", 1.5),
29    ("USD", 10),
30    USD=0.8,
31))
32
33def е_патриотична(amounts, exchange_rates):
34    amounts_in_lev = [amount / exchange_rates[currency] for currency, amount in amounts]
35    sum_in_lev = sum(amounts_in_lev)
36    rounded_to_stotinki = round(sum_in_lev, 2)
37    rounded_to_lev = round(sum_in_lev, 0)
38
39    if rounded_to_stotinki == rounded_to_lev:
40        return "ПАТРИОТИЧНА!"
41    return "НЕПАТРИОТИЧНА!"
42
43exchange_rates = {"EUR": 0.5, "USD": 0.6, "DKK": 3.8}
44amount = [("EUR", 1), ("USD", 3), ("DKK", 7.6), ("EUR", 3)]
45print(е_патриотична(amount, exchange_rates))
46
47amount = [("EUR", 1), ("USD", 2), ("DKK", 7.6), ("EUR", 3)]
48print(е_патриотична(amount, exchange_rates))

{'EUR': 0.5113, 'USD': 0.5982, 'DKK': 3.8226}
[('EUR', 8.0), ('USD', 12.5), ('DKK', 1.4286)]
[('BGN', 1.5), ('USD', 12.5)]
ПАТРИОТИЧНА!
НЕПАТРИОТИЧНА!
..........
----------------------------------------------------------------------
Ran 10 tests in 0.000s

OK

Дискусия
История
Това решение има само една версия.