How can I break down these problems into easier parts?
This is a key part of problem solving in programming, so be on the lookout for hints about how to break down the problem when going through the instructions. In the
digit_sum exercise, we know a few things:
- Our function takes some positive integer
- If we convert that input to a string using the built-in
str()function, we can iterate through it using a
for eachloop to get each “character” (digit) in the string.
- We can do something with each digit inside of that
- We must
returnthe result at the end, not inside of the loop.