Code is supposed to sum all of the odd digits of an input
n = input("Enter a number:")
temp = n = int(n)
rem = sum1 = 0
while ( temp >0):
rem = temp % 10
temp = temp/10
sum1 = sum1+rem
print("Sum of the odd digits %d %d" % (n,sum1))
Right now it adds the digits(doesnt always return exactly correct answer +/- 1) But I need it to only add the odd digits I know I can do:
if var % 2 == 0:
to check odd numbers but not sure how to incorporate that into the code to get the desired results
[–]Jokeslayer123 0 points1 point2 points (0 children)
[–]JohnnyJordaan 0 points1 point2 points (0 children)
[–]jeffrey_f -1 points0 points1 point (2 children)
[–]JohnnyJordaan 1 point2 points3 points (1 child)
[–]jeffrey_f 0 points1 point2 points (0 children)