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

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

5 точки общо

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

 1from collections import defaultdict
 2from functools import reduce
 3
 4def курс_в_лева(ex_rates):
 5    return {currency: round(1/rate, 4) for currency, rate in ex_rates.items()}
 6
 7def валута_към_левчета(*currencies, **ex_rates):
 8    result = defaultdict(float)
 9    for type, amount in currencies:
10        if type == 'BGN':
11            result[type] += amount
12        else:
13            result[type] += amount / ex_rates[type]
14    return {currency: round(amount, 4) for currency, amount in result.items()}
15    
16def е_патриотична(amounts, ex_rates):
17    amount_in_bgn = reduce(lambda x, y: x + y, [value / ex_rates[type] for type, value in amounts])
18    return "ПАТРИОТИЧНА!" if round(amount_in_bgn*1000, 0) == round(amount_in_bgn, 2) * 1000 else "НЕПАТРИОТИЧНА!"

......FF..
======================================================================
FAIL: test_е_патриотична_стотинки (test.TestЕПатриотична.test_е_патриотична_стотинки)
The total should be evaluated with a precision of 2 digits after the decimal point.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 132, in test_е_патриотична_стотинки
self.assertEqual("ПАТРИОТИЧНА!", патриотична)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 'ПАТРИОТИЧНА!' != 'НЕПАТРИОТИЧНА!'
- ПАТРИОТИЧНА!
+ НЕПАТРИОТИЧНА!
? ++

======================================================================
FAIL: test_е_патриотична_цели (test.TestЕПатриотична.test_е_патриотична_цели)
The total should be evaluated by means of whether the sum is a round number.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 124, in test_е_патриотична_цели
self.assertEqual("НЕПАТРИОТИЧНА!", непатриотична)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 'НЕПАТРИОТИЧНА!' != 'ПАТРИОТИЧНА!'
- НЕПАТРИОТИЧНА!
? --
+ ПАТРИОТИЧНА!

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

FAILED (failures=2)

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