Digit_sum


#1




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


return total


def digit_sum(n):
    if n==int:
        string=str(n)
        total=0
        for c in string:
            int(c)
            total+=c
        return total


#2

int is a data type, but checking if an integer equals a data type is false.

Two options: the exercise doesn't need validiation if the number is an integer, you can remove

Make a good comparison


#3

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