Okay so I figured out how to get the answer they are looking for
def digit_sum(n): x = str(n) n = 0 for y in x: n += int(y) return n
However, I looked into the hint box and there is a challenge where it asks you to use modulo and floor division
If you're looking for a challenge, try this: to get the rightmost digit of a number, you can modulo (%) the number by 10. To remove the rightmost digit you can floor divide (//) the number by 10. (Don't worry if you're not familiar with floor division—you can look up the documentation here. Remember, this is a challenge!)
Try working this into a pattern to isolate all of the digits and add them to a total.
I am wondering how this would be done? My thoughts is that you would probably want to use a for/if-break loop. to take the numbers seperately, add them into a variable and break once your it hits a 0. But I have no idea how I would get it to loop once as
x % 10
then the next time it loops do
(x // 10) % 10
and then continue to add ") // 10)" until it breaks by receiving '0'.
I'm not sure if I have completely over thought this or if I am totally on the wrong track. Help would be appreciated more than a straight answer, but if you can explain the answer that would be fine aswell.