Table of Contents
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.
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)
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.