Домашни > Да върнем левчето обратно! > Решения > Решението на Владимир Апостолов

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

5 точки общо

9 успешни теста
1 неуспешни теста
Код (third attempt)

 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

Как да проверя резултатите от тестовете? Нали имаше автоматични тестове Също има грешка в примерните резултати на втората функция
История

f1def курс_в_лева(dictionary):f1def курс_в_лева(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]
t5        result[key] = round(to_leva, 4)t5        result[key] = round(to_leva , 4)
6    return result6    return result
77
8def валута_към_левчета(*args,**kwargs):8def валута_към_левчета(*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_leva20                            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]
2424
2525
26def е_патриотична(list_,dictionary):26def е_патриотична(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 = 033    total = 0
34    for value in sum:34    for value in sum:
35        total += value35        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
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

t1def курс_в_лева(dictionary):t1def курс_в_лева(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 result6    return result
77
8def валута_към_левчета(*args,**kwargs):8def валута_към_левчета(*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_leva20                            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]
2424
2525
26def е_патриотична(list_,dictionary):26def е_патриотична(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 = 033    total = 0
34    for value in sum:34    for value in sum:
35        total += value35        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
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

f1def курс_в_лева(dictionary):f1def курс_в_лева(dictionary):
n2    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 result6    return result
107
11def валута_към_левчета(*args,**kwargs):8def валута_към_левчета(*args,**kwargs):
n12    to_return=[]n9    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]:
n19                    to_return.append([arg[0], to_leva])n16                    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_leva20                            new_amount = money[1] + to_leva
n24                            to_return[to_return.index(money)] = [money[0], new_amount]n21                            to_return[to_return.index(money)] = [money[0] , new_amount]
25    22    
n26    for item in to_return:n23    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
3024
3125
32def е_патриотична(list_,dictionary):26def е_патриотична(list_,dictionary):
n33    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 = 033    total = 0
43    for value in sum:34    for value in sum:
44        total += value35        total += value
n45    total=round(total, 2)n36    total = round(total, 2)
46    37    
t47    if total == round(total, 0):t38    if total == round(total , 0):
48        return "ПАТРИОТИЧНА!"39        return "ПАТРИОТИЧНА!"
49    else:40    else:
50        return "НЕПАТРИОТИЧНА!"41        return "НЕПАТРИОТИЧНА!"
51    42    
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op