Solving digit sum using str()


#1

Anyone know how to solve this problem using str()? Tutorial never had anything even closely related to this problem, so i don’t mind to skip this. Just would like to know if its even possible.


FAQ: Learn Python - Practice Makes Perfect - digit_sum
#2

yes, i know how to solve the problem using string. But the guidelines prevent me from just sharing the solution.

the practice makes perfect is really about the loose concepts you learned and pull it together, which can be challenging. But this is what programming is about: problem solving.

once you have a string, you can loop over the string:

for digit in "1234":

given the function gets integers, you need to convert to string, given you can’t loop over integers:

for digit in 1234: # gives error

#3

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