# Digit_sum - 4/15 - still lost

#1

My last thread closed due to inactivity.
I took a week off from this because it was so discouraging for such an apparently simple exercise to be so baffling.

``````def digit_sum(n):
sum_n = 0
str_n = str(n)
for x in str_n:
int_x = int(x)
int_x += sum_n
print sum_n

print digit_sum(1234)
#str_n = "1234"
#int_n = 1234
``````

…and at least I stopped getting that “line 5, can’t assign to function call” error, but now I get:

``````0
None
0
0
``````

and at the bottom, it says:

Your function fails on digit_sum(434). It returns None when it should return 11.

I feel completely lost. How is this one so hard if everybody thinks it’s so simple? Ionatan suggested I didn’t need any technical help–that I already know everything I need to know to do this, but I don’t have a single thought in my head that points me in any direction (let alone the right one).

Update: I broke down and clicked the “solution” button and–what is this?

``````def digit_sum(x):
total = 0
while x > 0:
total += x % 10
x = x // 10
print x
``````

This… what? I mean–I can’t even–I wasn’t even a tiny bit close. I’m over here assigning variables and switching things back and forth from integers to strings (for reasons I don’t understand) and the solution is over here using greater-than and modulo and this double-slash thing, whatever that is. It looks like they said a thing equals itself divided by ten? What?

Am I exceptionally bad at this? Do other people struggle this much?

I’d still like to solve this exercise before I proceed. Seeing the solution only made me feel more lost. Any advice would be appreciated.

#2

2 posts were merged into an existing topic: 4/15 - “digit_sum” - Don’t know how to start and the hint only confused me more

#3