Digit Sum: Correct Number is Printed but Says Incorrect Number is Returned


#1

My function works and prints out the proper number but it is always saying that it is not returning the correct number.

new_list=[]
def digit_sum(x):
    for number in str(x):
        new_list.append(int(number))
    sum_of_digits=sum(new_list)
    return sum_of_digits
        
print digit_sum(434)

#5

The list needs to be defined inside the function so it does not carry over previous values from earlier calls.


#6

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