1def курс_в_лева(dictionary):
2 result = {}
3 for key in dictionary:
4 to_leva = 1 / dictionary[key]
5 result[key] = round(to_leva , 4)
6 return result
7
8def валута_към_левчета(*args,**kwargs):
9 to_return = []
10
11 for arg in args:
12 for key in kwargs:
13 if arg[0] == key:
14 to_leva = arg[1] / kwargs[key]
15 if arg[0] not in [item[0] for item in to_return]:
16 to_return.append([arg[0] , to_leva])
17 else:
18 for money in to_return:
19 if money[0] == key:
20 new_amount = money[1] + to_leva
21 to_return[to_return.index(money)] = [money[0] , new_amount]
22
23 return [ (item[0] , round(item[1] , 4)) for item in to_return]
24
25
26def е_патриотична(list_,dictionary):
27 sum=[]
28 for money,value in list_:
29 for key in dictionary:
30 if money == key:
31 sum.append(value / dictionary[key])
32
33 total = 0
34 for value in sum:
35 total += value
36 total = round(total, 2)
37
38 if total == round(total , 0):
39 return "ПАТРИОТИЧНА!"
40 else:
41 return "НЕПАТРИОТИЧНА!"
42
....F.....
======================================================================
FAIL: test_валута_към_левчета_with_bgn (test.TestВалутаКъмЛевчета.test_валута_към_левчета_with_bgn)
Entries with BGN should be converted 1:1.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 73, in test_валута_към_левчета_with_bgn
self.assertContainersSomewhatEqual(expected_in_leva, in_leva)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/test.py", line 35, in assertContainersSomewhatEqual
raise AssertionError(
...<8 lines>...
)
AssertionError: Collections mismatch (type-independent):
Items in the first collection but not the second:
----------------------------------------------------------------------
Ran 10 tests in 0.001s
FAILED (failures=1)
Владимир Апостолов
06.03.2026 12:02Супер, има ли забележки към домашното? Какво мога да подобря?
|
Виктор Бечев
06.03.2026 11:29Автоматични тестове има - и те се използват за проверяване и оценяване на домашните. Публични стават чак след крайния срок. 🙂
|
Владимир Апостолов
06.03.2026 00:42Как да проверя резултатите от тестовете? Нали имаше автоматични тестове
Също има грешка в примерните резултати на втората функция
|
| f | 1 | def курс_в_лева(dictionary): | f | 1 | def курс_в_лева(dictionary): |
| 2 | result = {} | 2 | result = {} | ||
| 3 | for key in dictionary: | 3 | for key in dictionary: | ||
| 4 | to_leva = 1 / dictionary[key] | 4 | to_leva = 1 / dictionary[key] | ||
| t | 5 | result[key] = round(to_leva, 4) | t | 5 | result[key] = round(to_leva , 4) |
| 6 | return result | 6 | return result | ||
| 7 | 7 | ||||
| 8 | def валута_към_левчета(*args,**kwargs): | 8 | def валута_към_левчета(*args,**kwargs): | ||
| 9 | to_return = [] | 9 | to_return = [] | ||
| 10 | 10 | ||||
| 11 | for arg in args: | 11 | for arg in args: | ||
| 12 | for key in kwargs: | 12 | for key in kwargs: | ||
| 13 | if arg[0] == key: | 13 | if arg[0] == key: | ||
| 14 | to_leva = arg[1] / kwargs[key] | 14 | to_leva = arg[1] / kwargs[key] | ||
| 15 | if arg[0] not in [item[0] for item in to_return]: | 15 | if arg[0] not in [item[0] for item in to_return]: | ||
| 16 | to_return.append([arg[0] , to_leva]) | 16 | to_return.append([arg[0] , to_leva]) | ||
| 17 | else: | 17 | else: | ||
| 18 | for money in to_return: | 18 | for money in to_return: | ||
| 19 | if money[0] == key: | 19 | if money[0] == key: | ||
| 20 | new_amount = money[1] + to_leva | 20 | new_amount = money[1] + to_leva | ||
| 21 | to_return[to_return.index(money)] = [money[0] , new_amount] | 21 | to_return[to_return.index(money)] = [money[0] , new_amount] | ||
| 22 | 22 | ||||
| 23 | return [ (item[0] , round(item[1] , 4)) for item in to_return] | 23 | return [ (item[0] , round(item[1] , 4)) for item in to_return] | ||
| 24 | 24 | ||||
| 25 | 25 | ||||
| 26 | def е_патриотична(list_,dictionary): | 26 | def е_патриотична(list_,dictionary): | ||
| 27 | sum=[] | 27 | sum=[] | ||
| 28 | for money,value in list_: | 28 | for money,value in list_: | ||
| 29 | for key in dictionary: | 29 | for key in dictionary: | ||
| 30 | if money == key: | 30 | if money == key: | ||
| 31 | sum.append(value / dictionary[key]) | 31 | sum.append(value / dictionary[key]) | ||
| 32 | 32 | ||||
| 33 | total = 0 | 33 | total = 0 | ||
| 34 | for value in sum: | 34 | for value in sum: | ||
| 35 | total += value | 35 | total += value | ||
| 36 | total = round(total, 2) | 36 | total = round(total, 2) | ||
| 37 | 37 | ||||
| 38 | if total == round(total , 0): | 38 | if total == round(total , 0): | ||
| 39 | return "ПАТРИОТИЧНА!" | 39 | return "ПАТРИОТИЧНА!" | ||
| 40 | else: | 40 | else: | ||
| 41 | return "НЕПАТРИОТИЧНА!" | 41 | return "НЕПАТРИОТИЧНА!" | ||
| 42 | 42 |
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||
| t | 1 | def курс_в_лева(dictionary): | t | 1 | def курс_в_лева(dictionary): |
| 2 | result = {} | 2 | result = {} | ||
| 3 | for key in dictionary: | 3 | for key in dictionary: | ||
| 4 | to_leva = 1 / dictionary[key] | 4 | to_leva = 1 / dictionary[key] | ||
| 5 | result[key] = round(to_leva, 4) | 5 | result[key] = round(to_leva, 4) | ||
| 6 | return result | 6 | return result | ||
| 7 | 7 | ||||
| 8 | def валута_към_левчета(*args,**kwargs): | 8 | def валута_към_левчета(*args,**kwargs): | ||
| 9 | to_return = [] | 9 | to_return = [] | ||
| 10 | 10 | ||||
| 11 | for arg in args: | 11 | for arg in args: | ||
| 12 | for key in kwargs: | 12 | for key in kwargs: | ||
| 13 | if arg[0] == key: | 13 | if arg[0] == key: | ||
| 14 | to_leva = arg[1] / kwargs[key] | 14 | to_leva = arg[1] / kwargs[key] | ||
| 15 | if arg[0] not in [item[0] for item in to_return]: | 15 | if arg[0] not in [item[0] for item in to_return]: | ||
| 16 | to_return.append([arg[0] , to_leva]) | 16 | to_return.append([arg[0] , to_leva]) | ||
| 17 | else: | 17 | else: | ||
| 18 | for money in to_return: | 18 | for money in to_return: | ||
| 19 | if money[0] == key: | 19 | if money[0] == key: | ||
| 20 | new_amount = money[1] + to_leva | 20 | new_amount = money[1] + to_leva | ||
| 21 | to_return[to_return.index(money)] = [money[0] , new_amount] | 21 | to_return[to_return.index(money)] = [money[0] , new_amount] | ||
| 22 | 22 | ||||
| 23 | return [ (item[0] , round(item[1] , 4)) for item in to_return] | 23 | return [ (item[0] , round(item[1] , 4)) for item in to_return] | ||
| 24 | 24 | ||||
| 25 | 25 | ||||
| 26 | def е_патриотична(list_,dictionary): | 26 | def е_патриотична(list_,dictionary): | ||
| 27 | sum=[] | 27 | sum=[] | ||
| 28 | for money,value in list_: | 28 | for money,value in list_: | ||
| 29 | for key in dictionary: | 29 | for key in dictionary: | ||
| 30 | if money == key: | 30 | if money == key: | ||
| 31 | sum.append(value / dictionary[key]) | 31 | sum.append(value / dictionary[key]) | ||
| 32 | 32 | ||||
| 33 | total = 0 | 33 | total = 0 | ||
| 34 | for value in sum: | 34 | for value in sum: | ||
| 35 | total += value | 35 | total += value | ||
| 36 | total = round(total, 2) | 36 | total = round(total, 2) | ||
| 37 | 37 | ||||
| 38 | if total == round(total , 0): | 38 | if total == round(total , 0): | ||
| 39 | return "ПАТРИОТИЧНА!" | 39 | return "ПАТРИОТИЧНА!" | ||
| 40 | else: | 40 | else: | ||
| 41 | return "НЕПАТРИОТИЧНА!" | 41 | return "НЕПАТРИОТИЧНА!" | ||
| 42 | 42 |
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||
| f | 1 | def курс_в_лева(dictionary): | f | 1 | def курс_в_лева(dictionary): |
| n | 2 | if type(dictionary) is not dict: | n | ||
| 3 | return "Provide a dictionary" | ||||
| 4 | |||||
| 5 | result = {} | 2 | result = {} | ||
| 6 | for key in dictionary: | 3 | for key in dictionary: | ||
| 7 | to_leva = 1 / dictionary[key] | 4 | to_leva = 1 / dictionary[key] | ||
| 8 | result[key] = round(to_leva, 4) | 5 | result[key] = round(to_leva, 4) | ||
| 9 | return result | 6 | return result | ||
| 10 | 7 | ||||
| 11 | def валута_към_левчета(*args,**kwargs): | 8 | def валута_към_левчета(*args,**kwargs): | ||
| n | 12 | to_return=[] | n | 9 | to_return = [] |
| 13 | 10 | ||||
| 14 | for arg in args: | 11 | for arg in args: | ||
| 15 | for key in kwargs: | 12 | for key in kwargs: | ||
| 16 | if arg[0] == key: | 13 | if arg[0] == key: | ||
| 17 | to_leva = arg[1] / kwargs[key] | 14 | to_leva = arg[1] / kwargs[key] | ||
| 18 | if arg[0] not in [item[0] for item in to_return]: | 15 | if arg[0] not in [item[0] for item in to_return]: | ||
| n | 19 | to_return.append([arg[0], to_leva]) | n | 16 | to_return.append([arg[0] , to_leva]) |
| 20 | else: | 17 | else: | ||
| 21 | for money in to_return: | 18 | for money in to_return: | ||
| 22 | if money[0] == key: | 19 | if money[0] == key: | ||
| 23 | new_amount = money[1] + to_leva | 20 | new_amount = money[1] + to_leva | ||
| n | 24 | to_return[to_return.index(money)] = [money[0], new_amount] | n | 21 | to_return[to_return.index(money)] = [money[0] , new_amount] |
| 25 | 22 | ||||
| n | 26 | for item in to_return: | n | 23 | return [ (item[0] , round(item[1] , 4)) for item in to_return] |
| 27 | to_return[to_return.index(item)] = (item[0], round(item[1], 4)) | ||||
| 28 | |||||
| 29 | return to_return | ||||
| 30 | 24 | ||||
| 31 | 25 | ||||
| 32 | def е_патриотична(list_,dictionary): | 26 | def е_патриотична(list_,dictionary): | ||
| n | 33 | if type(list_) is not list or type(dictionary) is not dict: | n | ||
| 34 | return "Provide a list and a dictionary" | ||||
| 35 | |||||
| 36 | sum=[] | 27 | sum=[] | ||
| 37 | for money,value in list_: | 28 | for money,value in list_: | ||
| 38 | for key in dictionary: | 29 | for key in dictionary: | ||
| 39 | if money == key: | 30 | if money == key: | ||
| 40 | sum.append(value / dictionary[key]) | 31 | sum.append(value / dictionary[key]) | ||
| 41 | 32 | ||||
| 42 | total = 0 | 33 | total = 0 | ||
| 43 | for value in sum: | 34 | for value in sum: | ||
| 44 | total += value | 35 | total += value | ||
| n | 45 | total=round(total, 2) | n | 36 | total = round(total, 2) |
| 46 | 37 | ||||
| t | 47 | if total == round(total, 0): | t | 38 | if total == round(total , 0): |
| 48 | return "ПАТРИОТИЧНА!" | 39 | return "ПАТРИОТИЧНА!" | ||
| 49 | else: | 40 | else: | ||
| 50 | return "НЕПАТРИОТИЧНА!" | 41 | return "НЕПАТРИОТИЧНА!" | ||
| 51 | 42 |
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||