- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Check whether sum of digits at odd places of a number is divisible by K in Python

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 −

- total := 0, pos := 1
- while n > 0 , do
- if pos is odd, then
- total := total + (n mod 10)

- n := quotient of (n / 10)
- pos := pos + 1

- if pos is odd, then
- if total is divisible by k, then
- return True

- return False

Let us see the following implementation to get better understanding −

## Example Code

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))

## Input

2416, 5

## Output

True

- Related Articles
- Check whether product of digits at even places of a number is divisible by K in Python
- Check whether product of digits at even places is divisible by sum of digits at odd place of a numbers in Python
- Check if product of digits of a number at even and odd places is equal in Python
- Primality test for the sum of digits at odd places of a number in C++
- Find the sum of digits of a number at even and odd places in C++
- C Program to check if a number is divisible by sum of its digits
- Program to find number of consecutive subsequences whose sum is divisible by k in Python
- Python Program to check whether it is possible to make a divisible by 3 number using all digits in an array
- C Program to check if a number is divisible by any of its digits
- Sum of a two-digit number and the number obtained by reversing the digits is always divisible by?
- Check if N is divisible by a number which is composed of the digits from the set {A, B} in Python
- Program to check whether number is a sum of powers of three in Python
- Find number of substrings of length k whose sum of ASCII value of characters is divisible by k in C++
- Check whether the sum of absolute difference of adjacent digits is Prime or not in Python
- Maximize the number of sum pairs which are divisible by K in C++

Advertisements