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

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

6 точки общо

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

 1def курс_в_лева(exchange_rates):
 2    new_exchange_rates = {}
 3
 4    for key, value in exchange_rates.items():
 5        new_exchange_rates[key] = round(1 / value, 4)
 6
 7    return new_exchange_rates
 8
 9def валута_към_левчета(*amount_not_exchanged, **exchange_rates):
10    amount_exchanged = {}
11
12    for currency, amount in amount_not_exchanged:
13        if currency in amount_exchanged:
14            amount_exchanged[currency] += amount
15        else:
16            amount_exchanged[currency] = amount
17
18    for currency, amount in amount_exchanged.items():
19        if currency == 'BGN':
20            amount_exchanged[currency] = round(amount, 4)
21        else:
22            amount_exchanged[currency] = round(amount / exchange_rates[currency], 4)
23
24    return list(amount_exchanged.items())
25
26def е_патриотична(amount_not_exchanged, exchange_rates):
27    total_leva = 0
28
29    for currency, amount in amount_not_exchanged:
30        if currency == 'BGN':
31            total_leva += amount
32        else:
33            total_leva += amount / exchange_rates[currency]
34
35    total_leva = round(total_leva, 2)
36
37    if total_leva == round(total_leva):
38        return 'ПАТРИОТИЧНА!'
39    else:
40        return 'НЕПАТРИОТИЧНА!'

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

OK

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

f1def курс_в_лева(exchange_rates):f1def курс_в_лева(exchange_rates):
2    new_exchange_rates = {}2    new_exchange_rates = {}
33
4    for key, value in exchange_rates.items():4    for key, value in exchange_rates.items():
n5        new_exchange_rates[key] = round(1/value, 4)n5        new_exchange_rates[key] = round(1 / value, 4)
66
7    return new_exchange_rates7    return new_exchange_rates
88
9def валута_към_левчета(*amount_not_exchanged, **exchange_rates):9def валута_към_левчета(*amount_not_exchanged, **exchange_rates):
10    amount_exchanged = {}10    amount_exchanged = {}
1111
12    for currency, amount in amount_not_exchanged:12    for currency, amount in amount_not_exchanged:
13        if currency in amount_exchanged:13        if currency in amount_exchanged:
14            amount_exchanged[currency] += amount14            amount_exchanged[currency] += amount
15        else:15        else:
16            amount_exchanged[currency] = amount16            amount_exchanged[currency] = amount
1717
18    for currency, amount in amount_exchanged.items():18    for currency, amount in amount_exchanged.items():
19        if currency == 'BGN':19        if currency == 'BGN':
20            amount_exchanged[currency] = round(amount, 4)20            amount_exchanged[currency] = round(amount, 4)
21        else:21        else:
22            amount_exchanged[currency] = round(amount / exchange_rates[currency], 4)22            amount_exchanged[currency] = round(amount / exchange_rates[currency], 4)
2323
24    return list(amount_exchanged.items())24    return list(amount_exchanged.items())
2525
26def е_патриотична(amount_not_exchanged, exchange_rates):26def е_патриотична(amount_not_exchanged, exchange_rates):
27    total_leva = 027    total_leva = 0
2828
29    for currency, amount in amount_not_exchanged:29    for currency, amount in amount_not_exchanged:
30        if currency == 'BGN':30        if currency == 'BGN':
31            total_leva += amount31            total_leva += amount
32        else:32        else:
33            total_leva += amount / exchange_rates[currency]33            total_leva += amount / exchange_rates[currency]
3434
35    total_leva = round(total_leva, 2)35    total_leva = round(total_leva, 2)
3636
37    if total_leva == round(total_leva):37    if total_leva == round(total_leva):
n38        return "ПАТРИОТИЧНА!"n38        return 'ПАТРИОТИЧНА!'
39    else:39    else:
t40        return "НЕПАТРИОТИЧНА!"t40        return 'НЕПАТРИОТИЧНА!'
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op