Skip to content

Commit 73e9917

Browse files
committed
Add last_digit function with type hints and doctests
1 parent d1a9486 commit 73e9917

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

maths/last_digit.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
def last_digit(n: int) -> int:
2+
"""
3+
Return the last digit of a given integer.
4+
5+
>>> last_digit(1234)
6+
4
7+
>>> last_digit(-98)
8+
8
9+
>>> last_digit(0)
10+
0
11+
"""
12+
return abs(n) % 10

0 commit comments

Comments
 (0)