1def курс_в_лева(exchange_rates):
2 rates_in_levs = {}
3 for currency, value in exchange_rates.items():
4 rates_in_levs[currency] = round(1 / value, 4)
5 return rates_in_levs
6
7
8def валута_към_левчета(*args, **kwargs):
9 sum_of_currencies = {}
10 for currency, value in args:
11 if currency not in sum_of_currencies:
12 sum_of_currencies[currency] = 0
13 sum_of_currencies[currency] += value
14
15 sum_in_levs = []
16 for currency, value in sum_of_currencies.items():
17 if currency == "BGN":
18 levs = value
19 else:
20 levs = round(value / kwargs[currency], 4)
21 sum_in_levs.append((currency, levs))
22 return sum_in_levs
23
24
25def е_патриотична(amount, exchange_rates):
26 sum_of_levs = 0
27 for currency, value in amount:
28 if currency == "BGN":
29 sum_of_levs += value
30 else:
31 sum_of_levs += value / exchange_rates[currency]
32 sum_of_levs = round(sum_of_levs, 2)
33 if sum_of_levs.is_integer():
34 return "ПАТРИОТИЧНА!"
35 return "НЕПАТРИОТИЧНА!"
..........
----------------------------------------------------------------------
Ran 10 tests in 0.000s
OK
Виктор Бечев
11.03.2026 18:17Неточностите, които има в кода ти са масови и ще ги обсъдим след малко на лекцията.
|
| f | 1 | def курс_в_лева(exchange_rates): | f | 1 | def курс_в_лева(exchange_rates): |
| n | 2 | result = {} | n | 2 | rates_in_levs = {} |
| 3 | for currency, value in exchange_rates.items(): | 3 | for currency, value in exchange_rates.items(): | ||
| n | 4 | result[currency] = round(1 / value, 4) | n | 4 | rates_in_levs[currency] = round(1 / value, 4) |
| 5 | return result | 5 | return rates_in_levs | ||
| 6 | 6 | ||||
| 7 | 7 | ||||
| 8 | def валута_към_левчета(*args, **kwargs): | 8 | def валута_към_левчета(*args, **kwargs): | ||
| 9 | sum_of_currencies = {} | 9 | sum_of_currencies = {} | ||
| 10 | for currency, value in args: | 10 | for currency, value in args: | ||
| 11 | if currency not in sum_of_currencies: | 11 | if currency not in sum_of_currencies: | ||
| 12 | sum_of_currencies[currency] = 0 | 12 | sum_of_currencies[currency] = 0 | ||
| 13 | sum_of_currencies[currency] += value | 13 | sum_of_currencies[currency] += value | ||
| 14 | 14 | ||||
| n | 15 | result = [] | n | 15 | sum_in_levs = [] |
| 16 | for currency, value in sum_of_currencies.items(): | 16 | for currency, value in sum_of_currencies.items(): | ||
| 17 | if currency == "BGN": | 17 | if currency == "BGN": | ||
| 18 | levs = value | 18 | levs = value | ||
| 19 | else: | 19 | else: | ||
| 20 | levs = round(value / kwargs[currency], 4) | 20 | levs = round(value / kwargs[currency], 4) | ||
| t | 21 | result.append((currency, levs)) | t | 21 | sum_in_levs.append((currency, levs)) |
| 22 | return result | 22 | return sum_in_levs | ||
| 23 | 23 | ||||
| 24 | 24 | ||||
| 25 | def е_патриотична(amount, exchange_rates): | 25 | def е_патриотична(amount, exchange_rates): | ||
| 26 | sum_of_levs = 0 | 26 | sum_of_levs = 0 | ||
| 27 | for currency, value in amount: | 27 | for currency, value in amount: | ||
| 28 | if currency == "BGN": | 28 | if currency == "BGN": | ||
| 29 | sum_of_levs += value | 29 | sum_of_levs += value | ||
| 30 | else: | 30 | else: | ||
| 31 | sum_of_levs += value / exchange_rates[currency] | 31 | sum_of_levs += value / exchange_rates[currency] | ||
| 32 | sum_of_levs = round(sum_of_levs, 2) | 32 | sum_of_levs = round(sum_of_levs, 2) | ||
| 33 | if sum_of_levs.is_integer(): | 33 | if sum_of_levs.is_integer(): | ||
| 34 | return "ПАТРИОТИЧНА!" | 34 | return "ПАТРИОТИЧНА!" | ||
| 35 | return "НЕПАТРИОТИЧНА!" | 35 | return "НЕПАТРИОТИЧНА!" |
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||
| f | 1 | def курс_в_лева(exchange_rates): | f | 1 | def курс_в_лева(exchange_rates): |
| 2 | result = {} | 2 | result = {} | ||
| 3 | for currency, value in exchange_rates.items(): | 3 | for currency, value in exchange_rates.items(): | ||
| 4 | result[currency] = round(1 / value, 4) | 4 | result[currency] = round(1 / value, 4) | ||
| 5 | return result | 5 | return result | ||
| 6 | 6 | ||||
| 7 | 7 | ||||
| 8 | def валута_към_левчета(*args, **kwargs): | 8 | def валута_към_левчета(*args, **kwargs): | ||
| 9 | sum_of_currencies = {} | 9 | sum_of_currencies = {} | ||
| 10 | for currency, value in args: | 10 | for currency, value in args: | ||
| 11 | if currency not in sum_of_currencies: | 11 | if currency not in sum_of_currencies: | ||
| 12 | sum_of_currencies[currency] = 0 | 12 | sum_of_currencies[currency] = 0 | ||
| 13 | sum_of_currencies[currency] += value | 13 | sum_of_currencies[currency] += value | ||
| 14 | 14 | ||||
| 15 | result = [] | 15 | result = [] | ||
| n | 16 | n | |||
| 17 | for currency, value in sum_of_currencies.items(): | 16 | for currency, value in sum_of_currencies.items(): | ||
| 18 | if currency == "BGN": | 17 | if currency == "BGN": | ||
| 19 | levs = value | 18 | levs = value | ||
| 20 | else: | 19 | else: | ||
| 21 | levs = round(value / kwargs[currency], 4) | 20 | levs = round(value / kwargs[currency], 4) | ||
| 22 | result.append((currency, levs)) | 21 | result.append((currency, levs)) | ||
| 23 | return result | 22 | return result | ||
| 24 | 23 | ||||
| 25 | 24 | ||||
| 26 | def е_патриотична(amount, exchange_rates): | 25 | def е_патриотична(amount, exchange_rates): | ||
| 27 | sum_of_levs = 0 | 26 | sum_of_levs = 0 | ||
| 28 | for currency, value in amount: | 27 | for currency, value in amount: | ||
| 29 | if currency == "BGN": | 28 | if currency == "BGN": | ||
| 30 | sum_of_levs += value | 29 | sum_of_levs += value | ||
| 31 | else: | 30 | else: | ||
| 32 | sum_of_levs += value / exchange_rates[currency] | 31 | sum_of_levs += value / exchange_rates[currency] | ||
| 33 | sum_of_levs = round(sum_of_levs, 2) | 32 | sum_of_levs = round(sum_of_levs, 2) | ||
| 34 | if sum_of_levs.is_integer(): | 33 | if sum_of_levs.is_integer(): | ||
| 35 | return "ПАТРИОТИЧНА!" | 34 | return "ПАТРИОТИЧНА!" | ||
| t | 36 | else: | t | ||
| 37 | return "НЕПАТРИОТИЧНА!" | 35 | return "НЕПАТРИОТИЧНА!" |
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||