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

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

6 точки общо

10 успешни теста
0 неуспешни теста
Код

 1def курс_в_лева(exchange_rates):
 2    return {currency: round(1 / value, 4) for currency, value in exchange_rates.items()}
 3
 4# exchange_rates = {"EUR": 1.9558, "USD": 1.6718, "DKK": 0.2616}
 5# print(курс_в_лева(exchange_rates)) # {"EUR": 0.5113, "USD": 0.5982, "DKK": 3.8226}
 6
 7def валута_към_левчета(*amounts, **exchange_rates):
 8    exchange_rates["BGN"] = 1
 9    
10    amounts_unique = {currency: 0 for currency, _ in amounts}
11    for currency, value in amounts:
12        amounts_unique[currency] += value
13    
14    amounts_leva = [(currency, round(value / exchange_rates[currency], 4)) for currency, value in amounts_unique.items()]
15    return amounts_leva
16
17# print(валута_към_левчета(
18#     ("EUR", 1.5),
19#     ("USD", 10),
20#     ("DKK", 10),
21#     ("EUR", 2.5),
22#     EUR=0.5,
23#     USD=0.8,
24#     DKK=7,
25# ))
26
27def е_патриотична(amounts, exchange_rates):
28    amount_leva_sum = round(sum([value for _, value in валута_към_левчета(*amounts, **exchange_rates)]), 2)
29
30    if int(amount_leva_sum) == amount_leva_sum:
31        return "ПАТРИОТИЧНА!"
32    return "НЕПАТРИОТИЧНА!"
33
34# exchange_rates = {"EUR": 0.5, "USD": 0.6, "DKK": 3.8}
35# amounts = [("EUR", 1), ("USD", 3), ("DKK", 7.6), ("EUR", 3)]
36# print(е_патриотична(amounts, exchange_rates)) # ПАТРИОТИЧНА! - 4 / 0.5 + 3 / 0.6 + 7.6 / 3.8 = 15
37
38# amounts = [("EUR", 1), ("USD", 2), ("DKK", 7.6), ("EUR", 3)]
39# print(е_патриотична(amounts, exchange_rates)) # НЕПАТРИОТИЧНА! - 4 / 0.5 + 2 / 0.6 + 7.6 / 3.8 = 13.33, опитват се да ни измамят

..........
----------------------------------------------------------------------
Ran 10 tests in 0.000s

OK

Дискусия
История

f1def курс_в_лева(exchange_rates):f1def курс_в_лева(exchange_rates):
2    return {currency: round(1 / value, 4) for currency, value in exchange_rates.items()}2    return {currency: round(1 / value, 4) for currency, value in exchange_rates.items()}
33
4# exchange_rates = {"EUR": 1.9558, "USD": 1.6718, "DKK": 0.2616}4# exchange_rates = {"EUR": 1.9558, "USD": 1.6718, "DKK": 0.2616}
5# print(курс_в_лева(exchange_rates)) # {"EUR": 0.5113, "USD": 0.5982, "DKK": 3.8226}5# print(курс_в_лева(exchange_rates)) # {"EUR": 0.5113, "USD": 0.5982, "DKK": 3.8226}
66
7def валута_към_левчета(*amounts, **exchange_rates):7def валута_към_левчета(*amounts, **exchange_rates):
8    exchange_rates["BGN"] = 18    exchange_rates["BGN"] = 1
9    9    
10    amounts_unique = {currency: 0 for currency, _ in amounts}10    amounts_unique = {currency: 0 for currency, _ in amounts}
11    for currency, value in amounts:11    for currency, value in amounts:
12        amounts_unique[currency] += value12        amounts_unique[currency] += value
13    13    
14    amounts_leva = [(currency, round(value / exchange_rates[currency], 4)) for currency, value in amounts_unique.items()]14    amounts_leva = [(currency, round(value / exchange_rates[currency], 4)) for currency, value in amounts_unique.items()]
15    return amounts_leva15    return amounts_leva
1616
17# print(валута_към_левчета(17# print(валута_към_левчета(
18#     ("EUR", 1.5),18#     ("EUR", 1.5),
19#     ("USD", 10),19#     ("USD", 10),
20#     ("DKK", 10),20#     ("DKK", 10),
21#     ("EUR", 2.5),21#     ("EUR", 2.5),
22#     EUR=0.5,22#     EUR=0.5,
23#     USD=0.8,23#     USD=0.8,
24#     DKK=7,24#     DKK=7,
25# ))25# ))
2626
27def е_патриотична(amounts, exchange_rates):27def е_патриотична(amounts, exchange_rates):
t28    exchange_rates["BGN"] = 1t28    amount_leva_sum = round(sum([value for _, value in валута_към_левчета(*amounts, **exchange_rates)]), 2)
29    
30    amounts_unique = {currency: 0 for currency, _ in amounts}
31    for currency, value in amounts:
32        amounts_unique[currency] += value
33    
34    amount_leva_sum = round(sum([round((value / exchange_rates[currency]), 4) for currency, value in amounts_unique.items()]), 2)
3529
36    if int(amount_leva_sum) == amount_leva_sum:30    if int(amount_leva_sum) == amount_leva_sum:
37        return "ПАТРИОТИЧНА!"31        return "ПАТРИОТИЧНА!"
38    return "НЕПАТРИОТИЧНА!"32    return "НЕПАТРИОТИЧНА!"
3933
40# exchange_rates = {"EUR": 0.5, "USD": 0.6, "DKK": 3.8}34# exchange_rates = {"EUR": 0.5, "USD": 0.6, "DKK": 3.8}
41# amounts = [("EUR", 1), ("USD", 3), ("DKK", 7.6), ("EUR", 3)]35# amounts = [("EUR", 1), ("USD", 3), ("DKK", 7.6), ("EUR", 3)]
42# print(е_патриотична(amounts, exchange_rates)) # ПАТРИОТИЧНА! - 4 / 0.5 + 3 / 0.6 + 7.6 / 3.8 = 1536# print(е_патриотична(amounts, exchange_rates)) # ПАТРИОТИЧНА! - 4 / 0.5 + 3 / 0.6 + 7.6 / 3.8 = 15
4337
44# amounts = [("EUR", 1), ("USD", 2), ("DKK", 7.6), ("EUR", 3)]38# amounts = [("EUR", 1), ("USD", 2), ("DKK", 7.6), ("EUR", 3)]
45# print(е_патриотична(amounts, exchange_rates)) # НЕПАТРИОТИЧНА! - 4 / 0.5 + 2 / 0.6 + 7.6 / 3.8 = 13.33, опитват се да ни измамят39# print(е_патриотична(amounts, exchange_rates)) # НЕПАТРИОТИЧНА! - 4 / 0.5 + 2 / 0.6 + 7.6 / 3.8 = 13.33, опитват се да ни измамят
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op