| f | def validate_key(key): | f | def validate_key(key): |
| return isinstance(key,str) and len(key) == 3 | | return isinstance(key,str) and len(key) == 3 |
| | | |
| | | |
| def validate_value(value): | | def validate_value(value): |
| return isinstance(value, (float,int)) | | return isinstance(value, (float,int)) |
| | | |
| | | |
| def курс_в_лева(exchange_rates: dict[str,float])->dict[str,float]: | | def курс_в_лева(exchange_rates: dict[str,float])->dict[str,float]: |
| for key,value in exchange_rates.items(): | | for key,value in exchange_rates.items(): |
| if not (validate_key(key) and validate_value(value)): | | if not (validate_key(key) and validate_value(value)): |
| return | | return |
| | | |
| exchange_rates_in_bg={} | | exchange_rates_in_bg={} |
| for key,value in exchange_rates.items(): | | for key,value in exchange_rates.items(): |
| exchange_rates_in_bg[key] = round(1 / value, 4) | | exchange_rates_in_bg[key] = round(1 / value, 4) |
| | | |
| return exchange_rates_in_bg | | return exchange_rates_in_bg |
| | | |
| | | |
| def валута_към_левчета(*args,**kwargs): | | def валута_към_левчета(*args,**kwargs): |
| result={} | | result={} |
| curr_in_bgn = 0 | | curr_in_bgn = 0 |
| | | |
| for curr_element in args: | | for curr_element in args: |
| if not ( | | if not ( |
| isinstance(curr_element,tuple) | | isinstance(curr_element,tuple) |
| and len(curr_element) == 2 | | and len(curr_element) == 2 |
| and validate_key(curr_element[0]) | | and validate_key(curr_element[0]) |
| and validate_value(curr_element[1]) | | and validate_value(curr_element[1]) |
| ): | | ): |
| return | | return |
| | | |
| for key,value in kwargs.items(): | | for key,value in kwargs.items(): |
| if not validate_key(key) or not validate_value(value): | | if not validate_key(key) or not validate_value(value): |
| return | | return |
| | | |
| for currency, amount in args: | | for currency, amount in args: |
| if currency == "BGN": | | if currency == "BGN": |
| curr_in_bgn = amount | | curr_in_bgn = amount |
| elif currency in kwargs: | | elif currency in kwargs: |
| curr_in_bgn = amount / kwargs[currency] | | curr_in_bgn = amount / kwargs[currency] |
| else: | | else: |
| continue | | continue |
| | | |
| curr_in_bgn = round(curr_in_bgn, 4) | | curr_in_bgn = round(curr_in_bgn, 4) |
| if currency in result: | | if currency in result: |
| result[currency] += curr_in_bgn | | result[currency] += curr_in_bgn |
| else: | | else: |
| result[currency] = curr_in_bgn | | result[currency] = curr_in_bgn |
| return result | | return result |
| | | |
| | | |
| def е_патриотична(amount, exchange_rates): | | def е_патриотична(amount, exchange_rates): |
| if not (isinstance(amount, list) and isinstance(exchange_rates, dict)): | | if not (isinstance(amount, list) and isinstance(exchange_rates, dict)): |
| return | | return |
| for currency_and_money in amount: | | for currency_and_money in amount: |
| if not ( | | if not ( |
| isinstance(currency_and_money,tuple) | | isinstance(currency_and_money,tuple) |
| and len(currency_and_money) == 2 | | and len(currency_and_money) == 2 |
| and validate_key(currency_and_money[0]) | | and validate_key(currency_and_money[0]) |
| and validate_value(currency_and_money[1]) | | and validate_value(currency_and_money[1]) |
| ): | | ): |
| return | | return |
| | | |
| for key,value in exchange_rates.items(): | | for key,value in exchange_rates.items(): |
| if not (validate_key(key) and validate_value(value)): | | if not (validate_key(key) and validate_value(value)): |
| return | | return |
| | | |
| curr_in_bgn = 0 | | curr_in_bgn = 0 |
| | | |
| for currency, money in amount: | | for currency, money in amount: |
| t | if currency == "BGN": | t | if currency == "BGN": |
| curr_in_bgn += money | | curr_in_bgn += money |
| elif currency in exchange_rates: | | elif currency in exchange_rates: |
| curr_in_bgn += money / exchange_rates[currency] | | curr_in_bgn += money / exchange_rates[currency] |
| | | |
| if round(curr_in_bgn,2).is_integer(): | | if round(curr_in_bgn,2).is_integer(): |
| return "ПАТРИОТИЧНА!" | | return "ПАТРИОТИЧНА!" |
| else: | | else: |
| return "НЕПАТРИОТИЧНА!" | | return "НЕПАТРИОТИЧНА!" |
| | | |
| | | |
| | | |