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