4 Digit_sum


#1

This is a bit confusing and the hint doesn’t really help me much…

def digit_sum(n):
n = str(n)
total = 0
for i in n:
i = int(i)
total += i
return total

digit_sum(434)

It returns “4” instead of “11”


#2

Check where your return is. If inside the loop, take back some indent so it is not.


#3

It was inside the loop, it works perfectly now. Thanks! :slight_smile:


#4

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