Suppose we have a number n and another number k, we have to check whether the sum of digits of n at it's odd places (from right side to left side) is divisible by k or not.
So, if the input is like n = 2416 k = 5, then the output will be True as sum of odd placed numbers from right to left is 4 + 6 = 10. Which is divisible by 5.
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding −
def solve(n, k): total = 0 pos = 1 while n > 0: if pos % 2 == 1: total += n % 10 n = n // 10 pos += 1 if total % k == 0: return True return False n = 2416 k = 5 print(solve(n, k))