| n | | n | def is_exchange_rate_valid(exchange_rates): |
| | | for currency in exchange_rates: |
| | | if len(currency) != 3: |
| | | return False |
| | | if exchange_rates[currency] <= 0: |
| | | return False |
| | | return True |
| | | |
| def курс_в_лева(exchange_rates): | | def курс_в_лева(exchange_rates): |
| n | | n | if not is_exchange_rate_valid(exchange_rates): |
| | | return None |
| | | |
| result = {} | | result = {} |
| for currency in exchange_rates: | | for currency in exchange_rates: |
| n | if len(currency) != 3: | n | |
| return None | | |
| | | |
| if exchange_rates[currency] <= 0: | | |
| return None | | |
| | | |
| result[currency] = round(1 / exchange_rates[currency], 4) | | result[currency] = round(1 / exchange_rates[currency], 4) |
| return result | | return result |
| | | |
| def валута_към_левчета(*currencies, **exchange_rates): | | def валута_към_левчета(*currencies, **exchange_rates): |
| | | |
| n | | n | if not is_exchange_rate_valid(exchange_rates): |
| | | return None |
| | | |
| sum = {} | | sum = {} |
| for currency, amount in currencies: | | for currency, amount in currencies: |
| if currency not in sum: | | if currency not in sum: |
| sum[currency] = 0 | | sum[currency] = 0 |
| sum[currency] += amount | | sum[currency] += amount |
| | | |
| result = [] | | result = [] |
| for currency in sum: | | for currency in sum: |
| if currency == "BGN": | | if currency == "BGN": |
| result.append((currency, sum[currency])) | | result.append((currency, sum[currency])) |
| else: | | else: |
| result.append((currency, round(sum[currency] / exchange_rates[currency], 4))) | | result.append((currency, round(sum[currency] / exchange_rates[currency], 4))) |
| return result | | return result |
| | | |
| def е_патриотична(currencies, exchange_rates): | | def е_патриотична(currencies, exchange_rates): |
| | | |
| n | | n | if not is_exchange_rate_valid(exchange_rates): |
| | | return None |
| | | |
| total_sum = 0 | | total_sum = 0 |
| | | |
| for currency, amount in currencies: | | for currency, amount in currencies: |
| if currency == "BGN": | | if currency == "BGN": |
| total_sum += amount | | total_sum += amount |
| else: | | else: |
| total_sum += (amount / exchange_rates[currency]) | | total_sum += (amount / exchange_rates[currency]) |
| | | |
| rounded = round(total_sum, 2) | | rounded = round(total_sum, 2) |
| if rounded % 1 == 0: | | if rounded % 1 == 0: |
| return "ПАТРИОТИЧНА!" | | return "ПАТРИОТИЧНА!" |
| else: | | else: |
| return "НЕПАТРИОТИЧНА!" | | return "НЕПАТРИОТИЧНА!" |
| t | | t | |