Advertisement
MisterQuirk

Untitled

Apr 13th, 2024
819
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.91 KB | None | 0 0
  1. #Task 1
  2.  
  3. def sum_numbers(*numbers):
  4.     return sum(numbers)
  5.  
  6. #Task 2
  7.  
  8. def print_kwargs(**kwargs):
  9.     for line in kwargs:
  10.         print(f'{line}: {kwargs[line]}')
  11.  
  12.  
  13. #Task 3
  14.  
  15. def filter_by_length(min_length, *args):
  16.     ans = list()
  17.     for line in args:
  18.         if len(line) >= min_length:
  19.             ans.append(line)
  20.     return ans
  21.  
  22. #Task 4
  23.  
  24. def calculate_total_price(cost, **kwargs):
  25.     total_discount = 0
  26.     for item in kwargs:
  27.         total_discount += kwargs[item]
  28.     return cost - cost * (total_discount * 0.01)
  29.  
  30. #Task 5
  31.  
  32. def custom_print(*args, **kwargs):
  33.     endline = kwargs.get('end', '\n')
  34.     separator = kwargs.get('sep', ' ')
  35.  
  36.     arr = list()
  37.  
  38.     for line in args:
  39.         arr.append(str(line))
  40.  
  41.     for key, item in kwargs.items():
  42.         if key != 'sep' and key != 'end':
  43.             arr.append(f'{key} = {item}')
  44.  
  45.     print(separator.join(arr), end=endline)
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement