Exercise 1: Reverse the Digits of a Number — Possible Solution ==================================================================== n = 12345 reversed_number = 0 while n > 0: last_digit = n % 10 reversed_number = reversed_number * 10 + last_digit n //= 10 print(reversed_number) Example run: 54321 Same program with n = 1200: 21 WHY THIS WORKS AS AN ANSWER ------------------------------ n % 10 is the last digit and n //= 10 removes it, so the loop ends when no digits are left (n is 0). Each digit taken off is added to the END of the result: multiplying reversed_number by 10 shifts what is there one place left, then the new digit fills the units place. A five-digit number needs five passes and a seven-digit one needs seven, with no change to the code, which is why while fits. For 1200 the result is 21: the zeros come off first, and a number cannot have leading zeros, so they disappear. To keep them you would have to work with strings.