Sum of even & odd
Level EASY
Write a program to input an integer N and print the sum of all its even digits and sum of all its odd digits separately.
Digits mean numbers, not the places! That is, if the given integer is "13245", even digits are 2 & 4 and odd digits are 1, 3 & 5.
Input format :
Output format :
Constraints
Sample Input 1:
Sample Output 1:
Sample Input 2:
Sample Output 2:
Explanation for Input 2:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
num=input() | |
x=[int(i) for i in num] | |
e=0 | |
o=0 | |
for i in range(0,len(x)): | |
if x[i]%2==0: | |
e=e+x[i] | |
else: | |
o=o+x[i] | |
print(e,o) |
Comments
Post a Comment
Please give us your valuable feedback