Please explain this to me like I’m in the fifth grade. I’m trying to break this down on my own and the instructions are confusing as to how they came up with this solution.
How does this work exactly? Why do we define the total? Why did we go with a while loop? x % 10… Why? Floor division… Why?
Please explain this as simply as possible.
total = 0
while x > 0:
total += x % 10
x = x // 10