Python Program to Count rotations which are divisible by 10

Python Program to Count rotations which are divisible by 10

If you want to count the number of rotations of a given number that are divisible by 10, here's what you can do:

For a number to be divisible by 10, it should end in 0. So, when rotating, the only thing we need to check is how many times the number 0 appears in the given number (except the last position).

Let's consider an example:

Number: 5008 Rotations:

  • 5008 (Original, not counted)
  • 8500
  • 0850
  • 0085

Out of the above rotations, 8500 and 0850 are divisible by 10.

Here's a Python program to count the number of rotations of a number that are divisible by 10:

def count_rotations_divisible_by_10(n): # Convert the number to string s = str(n) # Count rotations which have 0 at the last position except original number count = 0 for i in range(len(s) - 1): # Excluding the last position if s[i] == '0': count += 1 return count # Test num = 5008 print(count_rotations_divisible_by_10(num)) # Expected output: 2 

The above program will count how many times '0' appears in all positions of the number, except the last one.


More Tags

ohhttpstubs mpi radio-group image-processing point-of-sale splunk value-initialization roguelike zope php-5.6

More Programming Guides

Other Guides

More Programming Examples