Reverse a Three-Digit Number
Programming Basics · Python
TASK
Problem
Given a positive three-digit integer, print its digits reversed as a number.
EXAMPLE
Example
307
703
LIMITS
Constraints
100 ≤ n ≤ 999
LEARN
Theory for this problem
+
`input()` reads data entered by the user. The result of `input()` is initially a string. `int()` converts a numeric string into an integer. The `+` operator adds numbers. The `*` operator multiplies numbers. The `//` operator performs integer division and keeps the whole-number part. The `%` operator returns the remainder after division. `print()` displays the program result. Print only what the problem statement requires.
**Connection to this task.** The `//` and `%` operators complement each other: the first gives the integer quotient and the second gives the remainder. This is useful when splitting a number into groups or digits. The expression `c * 100 + b * 10 + a` shows how this idea is applied to the task data.
NEED HELP?
Hints
+
['Extract hundreds, tens, and ones separately.']
ANSWER
Solution
+
n = int(input()) a = n // 100 b = n // 10 % 10 c = n % 10 print(c * 100 + b * 10 + a)