Hello everyone, I need your help! I can not understand why the error. Can you help me, please?

# Digit_sum - Your function fails on digit_sum(434). It returns [] when it should return 11

**stetim94**#2

to validate your function works correctly, the exercise will call the function multiply times (not the whole script). So make sure that everything you use to get the digit_sum, is inside your function

Thanks for your quick reply!

Your suggestion is to put all the code inside the function?

The error continues ...

I apologize if I did not understand your tip!

**stetim94**#4

with the exception of raw_input, given the exercise calls the function multiply times, you don't want to overwrite the function parameter.

place raw_input between line 9 and 10 (outside the function, so no indent) and pass the variable you store the input in as argument when calling the function (you do this already)

**stetim94**#6

yep, but i hadn't seen yet you made another mistake.

Line 2, you use numeros, which means your function only works for what the user enters when prompted, but as we discussed, the exercise is going to call the function multiply times

So, instead use the function parameter, so your function works for any number supplied as argument when calling the function:

```
# your function is here, too lazy to type it all
numeros = raw_input("Enter a number: ")
digit_sum(numeros)
digit_sum("434")
digit_sum("12345")
```

see how i add (which the exercise does behind the scenes) multiply function calls? Your function should work for all this cases. (by using the function parameter, arguments supplied at function call are copied into the function parameter)

**stetim94**#8

can you copy paste your code to the forum? This an error i can't debug from just an image

Of course yes!

I choose print here because it is a way to see the code output and error message!

```
def digit_sum(numeros):
results = list(map(int, numeros))
print results
b = sum(results)
print b
return b
numeros = raw_input("Enter a number: ")
digit_sum(numeros)
```

**stetim94**#10

from the instructions:

For example: digit_sum(1234) should return 10 which is 1 + 2 + 3 + 4

1234 is a integer, raw_input gives a string.

to solve this problem, in the first line of your function cast numeros to a string

integers aren't iterable, that is why you get the error message

**textslayer78851**#11

Thanks for your patience!

Can you be a little clearer? I have tried to change the data type from int to str but the error continues. I'm getting crazy!

**textslayer78851**#13

TKS!

thank you very much for your help!

Giving only a few tips instead of solving the problem is the best way to learn more and better!

**system**#14

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.