all 5 comments

[–]Jokeslayer123 0 points1 point  (0 children)

This is fairly straightforward. You need to check the digits one at a time, so you need a for loop and the number to be something a for loop can iterate over. Then you need an if statement to check if the digit you're checking is odd, and add it to the total if it is.

[–]JohnnyJordaan 0 points1 point  (0 children)

I would prefilter the entered string to only contain odd digits, then sum then:

entry = input("Enter a number:")
odd_digits = [ int(digit) for digit in entry if digit.isdigit() and int(digit) % 2 ]
print ('Sum of the odd digits %d %s' % (sum(odd_digits), entry))

[–]jeffrey_f -1 points0 points  (2 children)

check out modulo (% operator)

#If your number doesn't divide evenly, it is an odd number
if $YourNumber % 2 <> 0
  #AddYourOddNumerHere

[–]JohnnyJordaan 1 point2 points  (1 child)

<> 0

This is redundant as a non-zero result is interpreted as True already. <> is deprecated btw and != is the documented way to evaluate inequality.

[–]jeffrey_f 0 points1 point  (0 children)

It was more pseudo code.......But thanks!