| f | #def test_alternative(exchange_rates): | f | #def test_alternative(exchange_rates): |
| # for currency in exchange_rates: | | # for currency in exchange_rates: |
| # if type(currency) == str and len(currency) == 3: | | # if type(currency) == str and len(currency) == 3: |
| # exchange_rates[currency] = round(1 / exchange_rates[currency], 4) | | # exchange_rates[currency] = round(1 / exchange_rates[currency], 4) |
| # | | # |
| # return exchange_rates | | # return exchange_rates |
| | | |
| def курс_в_лева(exchange_rates): | | def курс_в_лева(exchange_rates): |
| for currency, rate in exchange_rates.items(): | | for currency, rate in exchange_rates.items(): |
| if type(currency) == str and len(currency) == 3: | | if type(currency) == str and len(currency) == 3: |
| exchange_rates[currency] = round(1 / rate, 4) | | exchange_rates[currency] = round(1 / rate, 4) |
| | | |
| return exchange_rates | | return exchange_rates |
| | | |
| | | |
| def валута_към_левчета(*args, **kwargs): | | def валута_към_левчета(*args, **kwargs): |
| input_sum = {} | | input_sum = {} |
| | | |
| for pair in args: | | for pair in args: |
| if pair[0] not in input_sum: | | if pair[0] not in input_sum: |
| input_sum[pair[0]] = 0 | | input_sum[pair[0]] = 0 |
| | | |
| input_sum[pair[0]] += pair[1] | | input_sum[pair[0]] += pair[1] |
| | | |
| n | | n | |
| | | res = [(currency, round(value if currency == 'BGN' else value / kwargs[currency], 4)) |
| | | for currency, value in input_sum.items()] |
| res = [] | | #res = [] |
| for currency in input_sum: | | #for currency in input_sum: |
| if currency == 'BGN': | | # if currency == 'BGN': |
| value = round(input_sum[currency], 4) | | # value = round(input_sum[currency], 4) |
| res.append((currency, value)) | | # res.append((currency, value)) |
| else: | | # else: |
| value = round(input_sum[currency] / kwargs[currency], 4) | | # value = round(input_sum[currency] / kwargs[currency], 4) |
| res.append((currency, value)) | | # res.append((currency, value)) |
| | | |
| return res | | return res |
| | | |
| | | |
| def е_патриотична(amount, exchange_rates): | | def е_патриотична(amount, exchange_rates): |
| converted_input = валута_към_левчета(*amount, **exchange_rates) | | converted_input = валута_към_левчета(*amount, **exchange_rates) |
| final_sum = 0 | | final_sum = 0 |
| | | |
| for value in converted_input: | | for value in converted_input: |
| final_sum += value[1] | | final_sum += value[1] |
| | | |
| final_sum = round(final_sum, 2) | | final_sum = round(final_sum, 2) |
| | | |
| return "ПАТРИОТИЧНА!" if final_sum % 1 == 0 else "НЕПАТРИОТИЧНА!" | | return "ПАТРИОТИЧНА!" if final_sum % 1 == 0 else "НЕПАТРИОТИЧНА!" |
| t | | t | |
| | | |
| | | |
| amount = [("EUR", 1), ("USD", 3), ("DKK", 7.6), ("EUR", 3)] | | |
| exchange_rates = {"EUR": 0.5, "USD": 0.6, "DKK": 3.8} | | |
| print(е_патриотична(amount, exchange_rates)) | | |