First Digit of a Four-Digit Number
Programming Basics · Python
TASK
Problem
A positive four-digit integer `n` is read from input. Print its first digit.
EXAMPLE
Example
5832
5
LIMITS
Constraints
1000 ≤ n ≤ 9999
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 performs integer division and keeps the whole-number part. `print()` displays the program result. Print only what the problem statement requires.
**Connection to this task.** The `//` operator performs floor integer division. It is useful for counting how many complete groups of a fixed size fit into a value. The expression `n // 100` shows how this idea is applied to the task data.
For this task, pay special attention to `int(input())`: it connects the concept above to the concrete computation or program action.
**Focus: “First Digit of a Four-Digit Number”.** The same basic mechanism is used in a different context here, so understand the operation itself rather than memorizing a finished line of code.
NEED HELP?
Hints
+
['Integer division of a four-digit number by 1000 leaves only the leading digit.']
ANSWER
Solution
+
n = int(input()) first_digit = n // 1000 print(first_digit)