Select Page

# Program to check if the difference between sum of odd indexed digits and sum of even indexed digits is zero or not using Python

by | Jul 20, 2021 | Python Programs

Home » Python » Python Programs » Program to check if the difference between sum of odd indexed digits and sum of even indexed digits is zero or not using Python

## Introduction

The task is to find whether the difference of sum of odd positioned digits and sum of even positioned digits is zero for a given number. ## Program

```def check(ip_no):
if (ip_no % 11 == 0):
print("The difference between sum of odd digits and even digits is zero!")
else:
print("The difference between sum of odd digits and even digits is not zero!")

ip_no = int(input("Enter the number: "))
check(ip_no)```

## Output ## Explanation

In the above code, the approach is: if the given number is divisible by 11, then the difference between the sum of even positioned and odd positioned digits is zero.

Another approach can be, by traversing and adding all the elements at odd position and traversing and adding all the elements at even position. At the end find the difference, and check if difference is equalled to zero.

## Author

• A Full Stack Developer with 10+ years of experience in technical content creation.

• 