The code works, but I get an error message!


I get this error message:
"Oops, try again. Your function fails on digit_sum(434). It returns None when it should return 11."

But both the terminal and Spyder print 11 to digit_sum(434)! What's wrong with my code? Is this a bug?

def digit_sum(n):
    total = 0
    for digit in str(n):
        digit = int(digit)
        total += digit
    print total


Oh, I figured it out. I had to return it instead of printing. Sorry, guys!


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