I got frustrated using the str to int method (i couldn't get the split function to work) so I am trying the 'challenge' method involving using modulo to seperate digits and add them together.
I wrote a code that I think should work (at least for three digit numbers so far) but I receive an error:
"Oops, try again. Your function fails on digit_sum(434). It returns 7 when it should return 11."
Here's my code:
def digit_sum(n): first_digit = n % 10 a = n - first_digit second_digit = (a % 100)/10 b = a % 100 c = a - b third_digit = b / 100 return first_digit + second_digit + third_digit
I apologize if it's confusing, but when I work out the code manually on paper I should get the intended answer.
Thanks for the help!