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

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

5 точки общо

8 успешни теста
2 неуспешни теста
Код

 1"""This file Contains the first homework."""
 2
 3
 4def курс_в_лева(exchange_rates):
 5    """Конвертира във вида "чуждестранна валута за едно левче"."""
 6    return {
 7        currency: round(1 / rate, 4)
 8        for currency, rate in exchange_rates.items()
 9    }
10
11
12def валута_към_левчета(*currency_items, **currency_count_per_lev):
13    """Сумирани всички единици от дадената валута и конвертирани в лева."""
14    to_lev = {}
15    currency_count_per_lev['BGN'] = 1
16    for currency, count in currency_items:
17        adding = round(count / currency_count_per_lev[currency], 4)
18        if currency in to_lev:
19            if (currency):
20                to_lev[currency] += adding
21        else:
22            to_lev[currency] = adding
23
24    return to_lev
25
26
27def е_патриотична(amount, exchange_rates):
28    """Сумата на всички пари в списъка."""
29    total = sum(
30        round(value / exchange_rates[currency], 2)
31        for currency, value in amount
32    )
33    return 'ПАТРИОТИЧНА' if total % 1 == 0 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 118, in test_е_патриотична_цели
self.assertEqual("ПАТРИОТИЧНА!", патриотична)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 'ПАТРИОТИЧНА!' != 'ПАТРИОТИЧНА'
- ПАТРИОТИЧНА!
? -
+ ПАТРИОТИЧНА

----------------------------------------------------------------------
Ran 10 tests in 0.002s

FAILED (failures=2)

Дискусия
Милка Кръстева
09.03.2026 23:23

Благодаря много за feedback-a, ще кача нова версия с поправките.
История

f1"""This file Contains the first homework."""f1"""This file Contains the first homework."""
22
33
4def курс_в_лева(exchange_rates):4def курс_в_лева(exchange_rates):
5    """Конвертира във вида "чуждестранна валута за едно левче"."""5    """Конвертира във вида "чуждестранна валута за едно левче"."""
6    return {6    return {
n7        currency: round(1/rate, 4)n7        currency: round(1 / rate, 4)
8        for currency, rate in exchange_rates.items()8        for currency, rate in exchange_rates.items()
n9        }n9    }
1010
1111
12def валута_към_левчета(*currency_items, **currency_count_per_lev):12def валута_към_левчета(*currency_items, **currency_count_per_lev):
13    """Сумирани всички единици от дадената валута и конвертирани в лева."""13    """Сумирани всички единици от дадената валута и конвертирани в лева."""
14    to_lev = {}14    to_lev = {}
15    currency_count_per_lev['BGN'] = 115    currency_count_per_lev['BGN'] = 1
16    for currency, count in currency_items:16    for currency, count in currency_items:
n17        adding = round(count/currency_count_per_lev[currency], 4)n17        adding = round(count / currency_count_per_lev[currency], 4)
18        if currency in to_lev:18        if currency in to_lev:
19            if (currency):19            if (currency):
20                to_lev[currency] += adding20                to_lev[currency] += adding
21        else:21        else:
22            to_lev[currency] = adding22            to_lev[currency] = adding
2323
24    return to_lev24    return to_lev
2525
2626
27def е_патриотична(amount, exchange_rates):27def е_патриотична(amount, exchange_rates):
28    """Сумата на всички пари в списъка."""28    """Сумата на всички пари в списъка."""
29    total = sum(29    total = sum(
30        round(value / exchange_rates[currency], 2)30        round(value / exchange_rates[currency], 2)
31        for currency, value in amount31        for currency, value in amount
t32        )t32    )
33    return 'ПАТРИОТИЧНА' if total % 1 == 0 else 'НЕПАТРИОТИЧНА'33    return 'ПАТРИОТИЧНА' if total % 1 == 0 else 'НЕПАТРИОТИЧНА'
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op