# Digit_sum function take exactly one argument

#1

Hi,
Any idea why the following message appears:

# Oops, try again. Does your digit_sum function take exactly one argument (a positive integer)? Your code threw a "'int' object is not iterable" error.

Thanks

Note the code works fine with IDLE

``````Replace this line with your code.
def digit_sum(n):
total = 0
s = []
s[:] = list(n)
for x in s:
total = int(x) + total

number = input("Enter a number: ")
print(digit_sum(number))``````

#2

The program is meant to work with the parameter n, but looking through your loop function, it isn't.

So many issues, too. Please, look through the instructions.

#3

Thx for your response, I thought my function digit_sum took the parameter n.

I rewrote the exercise with the following code which works fine:
def digit_sum(n):
numberz = []
x = str(n)
for digit in x:
numberz.append(int(digit))
print ("DEBUG: numberz", numberz) # returns numberz [9, 8, 7]
print (sum(numberz)) # returns 24
return sum(numberz)

number = input("Enter a number: ") # eg 987
digit_sum(number)

#4

Okay!

#5

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