Python program to print the sum of even and odd digits of a number

 

A program that takes the input of an integer N and prints the sum of all its even and odd digits separately.


Input format :
 Integer N
Output format :
Print even sum  <space>  odd sum
Sample Input 1:
1234
Sample Output 1:
6 4

Solution :

  1. N = int(input())
  2. temp = N
  3. E = 0
  4. O = 0

  5. while temp > 0:
  6.     a = temp // 10
  7.     b = temp % 10
  8.     temp = a
  9.     if b % 2 == 0:
  10.         E = E + b
  11.     else:
  12.         O = O + b
  13. print(str(E) + ' ' + str(O))
Try it >>
Previous Post Next Post