Largest Digit
Programming Basics · Python
TASK
Problem
Given a positive three-digit integer, print its largest digit without `max()`.
EXAMPLE
Example
583
8
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 performs integer division and keeps the whole-number part. The `%` operator returns the remainder after division. Comparison operators `==`, `!=`, `<`, `>`, `<=`, `>=` compare values and produce `True` or `False`. `if` checks a condition and runs its block when the condition is true. `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 `m` 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: “Largest Digit”.** 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
+
['Extract the three digits and compare them.']
ANSWER
Solution
+
n = int(input())
a = n // 100
b = n // 10 % 10
c = n % 10
m = a
if b > m:
m = b
if c > m:
m = c
print(m)