Домашни > Да върнем левчето обратно! > Решения > Решението на Цветинка Хаджиева

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

6 точки общо

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

 1def курс_в_лева(exchange_rates):
 2    result = {}
 3
 4    for currency, rate in exchange_rates.items():
 5        result[currency] = round(1 / rate, 4)
 6
 7    return result
 8
 9
10def валута_към_левчета(*amounts, **exchange_rates):
11    sums = {}
12
13    
14    for currency, amount in amounts:
15        if currency not in sums:
16            sums[currency] = 0
17        sums[currency] += amount
18
19    result = []
20
21    
22    for currency, amount in sums.items():
23        if currency == "BGN":
24            leva = round(amount, 4)
25        else:
26            leva = round(amount / exchange_rates[currency], 4)
27
28        result.append((currency, leva))
29
30    return result
31
32
33def е_патриотична(amounts, exchange_rates):
34    total = 0
35
36    
37    for currency, amount in amounts:
38        if currency == "BGN":
39            total += amount
40        else:
41            total += amount / exchange_rates[currency]
42
43    total = round(total, 2)
44
45    
46    if total == int(total):
47        return "ПАТРИОТИЧНА!"
48    else:
49        return "НЕПАТРИОТИЧНА!"

..........
----------------------------------------------------------------------
Ran 10 tests in 0.001s

OK

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