Digit sum


#1

I'm following this myself and was hoping someone could answer explain tome how the two parts of the code that turn (n) into a str and then back into integers works out.

Cheers


Digit_sum
#2

well, integers aren't iterable (you can't loop over them). So, you convert to string so you can loop over the numbers, but to do math you need integers, so you convert the individual numbers back to integers so you can add them to total


#3

I used for loop in this case, first converted n into char and then loop through each letter and converting it to a digit while adding up to a variable


#4

can you show the code?


#5

providing full code answers isn't according to the guidelines, please go here, select: make a new topic, fill in the details in the template so we can help you


#7

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