Домашни > Да върнем левчето обратно! > Решения > Решението на Гергана Димитрова

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

6 точки общо

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

 1from collections import defaultdict
 2
 3newDict = {}
 4def курс_в_лева(rates):
 5    for currency, rate in rates.items():
 6        newDict[currency] = round(1 / rate, 4)
 7    return newDict
 8
 9
10
11
12def валута_към_левчета(*args, **kwargs):
13    result_dict = defaultdict(float)
14    result_list = []
15    for currency, amount in args:
16        result_dict[currency] += amount
17
18    for currency, total_amount in result_dict.items():
19        if currency == "BGN":
20            result_list.append((currency, total_amount))
21        else: 
22            rate = kwargs[currency]
23            result_list.append((currency, round(total_amount / rate, 4)))
24    return result_list
25
26
27
28
29def е_патриотична(amount, exchange_rates):
30    total_amount = валута_към_левчета(*amount, **exchange_rates)
31    total_in_BGN = 0
32    for currency, total in total_amount:
33        total_in_BGN += total
34    if round(total_in_BGN,2).is_integer():
35        return "ПАТРИОТИЧНА!"
36    else:
37        return "НЕПАТРИОТИЧНА!"

..........
----------------------------------------------------------------------
Ran 10 tests in 0.000s

OK

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