Last Two Digits
Programming Basics · Python
TASK
Problem
Given a non-negative integer, print the number formed by its last two digits.
EXAMPLE
Example
12345
45
LIMITS
Constraints
n ≥ 0
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 returns the remainder after division. `print()` displays the program result. Print only what the problem statement requires.
**Connection to this task.** The `%` operator returns a division remainder. Therefore `n % k` is useful for divisibility checks and for working with the last digits of a number. The expression `n % 100` shows how this idea is applied to the task data.
NEED HELP?
Hints
+
['Remainder modulo 100 keeps the last two digits.']
ANSWER
Solution
+
n = int(input()) result = n % 100 print(result)