| f | def курс_в_лева(exchange_rates): | f | def курс_в_лева(exchange_rates): |
| return {currency: round(1 / value, 4) for currency, value in exchange_rates.items()} | | return {currency: round(1 / value, 4) for currency, value in exchange_rates.items()} |
| | | |
| # exchange_rates = {"EUR": 1.9558, "USD": 1.6718, "DKK": 0.2616} | | # exchange_rates = {"EUR": 1.9558, "USD": 1.6718, "DKK": 0.2616} |
| # print(курс_в_лева(exchange_rates)) # {"EUR": 0.5113, "USD": 0.5982, "DKK": 3.8226} | | # print(курс_в_лева(exchange_rates)) # {"EUR": 0.5113, "USD": 0.5982, "DKK": 3.8226} |
| | | |
| def валута_към_левчета(*amounts, **exchange_rates): | | def валута_към_левчета(*amounts, **exchange_rates): |
| exchange_rates["BGN"] = 1 | | exchange_rates["BGN"] = 1 |
| | | |
| amounts_unique = {currency: 0 for currency, _ in amounts} | | amounts_unique = {currency: 0 for currency, _ in amounts} |
| for currency, value in amounts: | | for currency, value in amounts: |
| amounts_unique[currency] += value | | amounts_unique[currency] += value |
| | | |
| amounts_leva = [(currency, round(value / exchange_rates[currency], 4)) for currency, value in amounts_unique.items()] | | amounts_leva = [(currency, round(value / exchange_rates[currency], 4)) for currency, value in amounts_unique.items()] |
| return amounts_leva | | return amounts_leva |
| | | |
| # print(валута_към_левчета( | | # print(валута_към_левчета( |
| # ("EUR", 1.5), | | # ("EUR", 1.5), |
| # ("USD", 10), | | # ("USD", 10), |
| # ("DKK", 10), | | # ("DKK", 10), |
| # ("EUR", 2.5), | | # ("EUR", 2.5), |
| # EUR=0.5, | | # EUR=0.5, |
| # USD=0.8, | | # USD=0.8, |
| # DKK=7, | | # DKK=7, |
| # )) | | # )) |
| | | |
| def е_патриотична(amounts, exchange_rates): | | def е_патриотична(amounts, exchange_rates): |
| t | exchange_rates["BGN"] = 1 | t | amount_leva_sum = round(sum([value for _, value in валута_към_левчета(*amounts, **exchange_rates)]), 2) |
| | | |
| amounts_unique = {currency: 0 for currency, _ in amounts} | | |
| for currency, value in amounts: | | |
| amounts_unique[currency] += value | | |
| | | |
| amount_leva_sum = round(sum([round((value / exchange_rates[currency]), 4) for currency, value in amounts_unique.items()]), 2) | | |
| | | |
| if int(amount_leva_sum) == amount_leva_sum: | | if int(amount_leva_sum) == amount_leva_sum: |
| return "ПАТРИОТИЧНА!" | | return "ПАТРИОТИЧНА!" |
| return "НЕПАТРИОТИЧНА!" | | return "НЕПАТРИОТИЧНА!" |
| | | |
| # exchange_rates = {"EUR": 0.5, "USD": 0.6, "DKK": 3.8} | | # exchange_rates = {"EUR": 0.5, "USD": 0.6, "DKK": 3.8} |
| # amounts = [("EUR", 1), ("USD", 3), ("DKK", 7.6), ("EUR", 3)] | | # amounts = [("EUR", 1), ("USD", 3), ("DKK", 7.6), ("EUR", 3)] |
| # print(е_патриотична(amounts, exchange_rates)) # ПАТРИОТИЧНА! - 4 / 0.5 + 3 / 0.6 + 7.6 / 3.8 = 15 | | # print(е_патриотична(amounts, exchange_rates)) # ПАТРИОТИЧНА! - 4 / 0.5 + 3 / 0.6 + 7.6 / 3.8 = 15 |
| | | |
| # amounts = [("EUR", 1), ("USD", 2), ("DKK", 7.6), ("EUR", 3)] | | # amounts = [("EUR", 1), ("USD", 2), ("DKK", 7.6), ("EUR", 3)] |
| # print(е_патриотична(amounts, exchange_rates)) # НЕПАТРИОТИЧНА! - 4 / 0.5 + 2 / 0.6 + 7.6 / 3.8 = 13.33, опитват се да ни измамят | | # print(е_патриотична(amounts, exchange_rates)) # НЕПАТРИОТИЧНА! - 4 / 0.5 + 2 / 0.6 + 7.6 / 3.8 = 13.33, опитват се да ни измамят |