Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 51k
Expand file tree
/
Copy pathremove_digit.py
More file actions
Latest commit
37 lines (32 loc) · 1.01 KB
/
Copy pathremove_digit.py
File metadata and controls
37 lines (32 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
defremove_digit(num: int) ->int:
"""
returns the biggest possible result
that can be achieved by removing
one digit from the given number
>>> remove_digit(152)
52
>>> remove_digit(6385)
685
>>> remove_digit(-11)
1
>>> remove_digit(2222222)
222222
>>> remove_digit("2222222")
Traceback (most recent call last):
TypeError: only integers accepted as input
>>> remove_digit("string input")
Traceback (most recent call last):
TypeError: only integers accepted as input
"""
ifnotisinstance(num, int):
raiseTypeError("only integers accepted as input")
else:
num_str=str(abs(num))
num_transpositions= [list(num_str) forcharinrange(len(num_str))]
forindexinrange(len(num_str)):
num_transpositions[index].pop(index)
returnmax(
int("".join(list(transposition))) fortranspositioninnum_transpositions
)
if__name__=="__main__":
__import__("doctest").testmod()