Difference between Sums of Odd and Even Digits in Python Last Updated : 20 Oct, 2023 Comments Improve Suggest changes Like Article Like Report Write a python program for a given long integer, we need to find if the difference between sum of odd digits and sum of even digits is 0 or not. The indexes start from zero (0 index is for the leftmost digit). Examples: Input: 1212112Output: YesExplanation:the odd position element is 2+2+1=5the even position element is 1+1+1+2=5the difference is 5-5=0 equal to zero . So print yes. Input:12345Output: NoExplanation:the odd position element is 1+3+5=9the even position element is 2+4=6the difference is 9-6=3 not equal to zero. So print no. Approach: One by one traverse digits and find the two sums. If the difference between two sums is 0, print yes, else no. Python # Python program for the above approach def isDiff0(n): first = 0 second = 0 flag = True while(n > 0): digit = n % 10 if(flag): first += digit else: second += digit if(flag): flag = False else: flag = True n = int(n/10) if(first-second == 0): return True return False # driver code n = 1243 if(isDiff0(n)): print("Yes") else: print("No") OutputYes Time Complexity: O(n), where n is the number of digits in the input number.Auxiliary Space: O(1) Please refer complete article on Difference between sums of odd and even digits for more details! Comment More infoAdvertise with us Next Article Difference between Sums of Odd and Even Digits in Python K kartik Follow Improve Article Tags : Python Practice Tags : python Similar Reads Find Average of a Number Digits in Python AIn this article, we will see how to find the average of the digits of a number in Python. Examples: Input: N = 642 Output: 4.0 Explanation: (6+4+2)/3 = 12/3 = 4.0 Input: N = 3504 Output: 3.0 Explanation: (3+5+0+4)/4 = 12/4 = 3.0Calculate the average of a number of digits in python if the number is 3 min read Sum Even and Odd Values with One For-Loop and No If-Condition Using Python Summing even and odd numbers in a list is a common programming task. Typically, we'd use an if condition to check whether a number is even or odd. However, we can achieve this in Python efficiently using arithmetic operators and list slicing, without relying on if conditions. In this article, we'll 4 min read Sort Even-Placed in Increasing and Odd-placed Elements in Decreasing Order - Python We need to sort the elements at even indices in increasing order and the elements at odd indices in decreasing order. For example, given a list [10, 3, 5, 8, 2, 7, 6, 1], the result should be [2, 8, 5, 7, 6, 3, 10, 1]. Let us explore different ways to achieve this in Python.Using List Comprehension 3 min read SymPy | Permutation.is_even() in Python Permutation.is_even() : is_even() is a sympy Python library function that checks whether the permutation is even. Syntax : sympy.combinatorics.permutations.Permutation.is_even() Return : true - if the permutation is even; otherwise false Code #1 : is_even() Example Python3 1=1 # Python code explaini 1 min read Filter Even Values from a List - Python The task of filtering even values from a list in Python involves selecting elements from the list that are even numbers. For example, given the list a = [1, 2, 3, 4, 5], the goal is to filter out the even values, resulting in a new list like this [2, 4].Using list comprehensionList comprehension pro 2 min read Like