Hi, I'm stuck on the digit_sum exercise in Practice Makes Perfect. I tried to follow the hint by attempting to convert the input number into a string, split the string into a list, convert each element in the list into an integer, and then sum all the integers in the list. This is the code I came up with:
def digit_sum(n): if n > 0: string = str(n) n_list = string.split() n_sum = sum(map(int, n_list)) return n_sum
It's not working but I can't for the life of me figure out why. I'm getting the error message 'Your function fails on digit_sum(434). It returns 434 when it should return 11', but I don't know why it's returning the original number. Any help would be very much appreciated, I'm fairly new to coding so I apologise if this is an obvious question.