Someone Help digit_sum


#1



I am just brain dead from looking at this code. help please.


It tells me:
Traceback (most recent call last):
File "python", line 8, in
File "python", line 5, in digit_sum
TypeError: int() argument must be a string or a number, not 'list'


def digit_sum(n):
    results = 0
    n = list(str(n))
    for i in n:
        int(n[0:len(n)])
    results = results + n
    print results
digit_sum(1234)
#Here I am attempting to call it 
.


Please Help


#2

Hello

Try these changes to fix error - TypeError: int() argument must be a string or a number, not 'list'.

results = []        #make empty list
for n in list(str(n)):       #turn it into string
    n = int(n[0:len(n)])   #then back into number
    results.append(n)    #add all of them to the empty list
n = sum(results)       #sum up all numbers in list
return n     #return the sum

print digit_sum(1234) #use any number

You had most of the code, just needed to change a few things.


#3

hello amazingmango!
you have make your code complex it is just a simple.
just try to converting the integer in number and then assigning a veriable to it. like a=str(n)
and then loop through that variable and put each character in another variable but dont forgot to convert in into int. it will help!


#4

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