2 ways to deal with digit_sum


#1

But still think the digit_sum2 function seems to be too complicated.
Is there any way to make it shorter and more clearly?


#2

digit_sum2 is very lengthy. simply declare a variable total and give it a value of zero

use a while loop to check if n is greater then zero, then use the remainder to calculate the last digit, add it total, then use floor division on the number


#3

Thank you very much!!


#4

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