Reverse a number

Read a whole number and print it with its digits in reverse order, as a number. Leading zeros disappear: 1200 becomes 21.

What to build

A loop that builds one number from another.

Requirements

  • Read the number.
  • Print its digits in reverse order, as a number.

Input

One whole number from 0 to 1000000000.

Output

The reversed number.

Constraints

The number is from 0 to 1000000000.

Example

Input:

1234

Output:

4321

Why it works

Multiplying the result by 10 makes room for the next digit, and leading zeros disappear because the result is a number, not text.

Examples

Example 1 · Input
1234
Expected output
4321
Example 2 · Input
1200
Expected output
21

Prompts inside input() are ignored when checking, so input("n: ") is fine.

Hints

Hint 1

Each round: reversed_n = reversed_n * 10 + n % 10.

Solution

Show one correct solution (try it yourself first)
n = int(input())
reversed_n = 0
while n > 0:
    reversed_n = reversed_n * 10 + n % 10
    n //= 10
print(reversed_n)

Lesson: Repeating with while →