easy +5 pts

Last Digit Extractor

Extract the last digit of any non-negative integer using simple arithmetic.

Write a function `last_digit(n: int) -> int` that takes a non-negative integer `n` and returns its last digit (the digit in the ones place). For example, the last digit of 1234 is 4, and the last digit of 0 is 0. You can assume the input is always a non-negative integer. The function should be implemented without converting `n` to a string.

Constraints

0 <= n <= 10^9

Example

>>> last_digit(1234)
4
>>> last_digit(0)
0
>>> last_digit(9)
9
5 points ~5 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

The last digit of a number in base 10 is the remainder when divided by 10.
Use the modulo operator `%`.
For n=0, the result is 0, which is consistent with the approach.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.