Nov-16-2019, 02:59 PM
Implement a function called sum_divisible_by_k(lst, k) which receives a list of numbers called lst and a positive number k, and returns the sum of all numbers in the list that are divisible by k.
• If there is no number divisible by k (for example when the list is empty), you will return 0. Example 1:
>>> result = sum_divisible_by_k([3, 6, 4, 10, 9], 3)
>>> print(result)
18
******************************************************\
• If there is no number divisible by k (for example when the list is empty), you will return 0. Example 1:
>>> result = sum_divisible_by_k([3, 6, 4, 10, 9], 3)
>>> print(result)
18
******************************************************\
def sum_divisible_by_k(lst, k): sum0=0 for num in lst: # replace this with your implementation if num%k==0: sum0=sum0+num return sum0/k result = (sum_divisible_by_k([3, 6, 4, 10, 9], 3)) print(result)