Digit_sum help!


#1

Hi I am really confused what to do? please help.


#2

You are overthinking this. Try following this template:

def FUNCTION(PARAMETER):
    VARIABLE = 0
    for INDIVIDUAL_ITEM in str(PARAMETER):
        VARIABLE += int(INDIVIDUAL_ITEM)
    return VARIABLE

Make sure not to just follow the template and move on. I want to make sure that you understand how and why this works. If you have any questions, just ask.


#3

When I tried this template, the error shows “Your function fails on digit_sum(434). It returns 4 when it should return 11.” It seems like the program didn’t loop through all the index in the str. Please help.


#4

show me the code please


#5

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