Skip to content

Commit 3a7a34d

Browse files
committed
Add TypeError check for invalid inputs
1 parent 470025a commit 3a7a34d

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

maths/perfect_cube.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,14 @@ def perfect_cube_binary_search(n: int) -> bool:
2626
>>> perfect_cube_binary_search("a")
2727
Traceback (most recent call last):
2828
...
29-
TypeError: '<=' not supported between instances of 'int' and 'str'
29+
TypeError: perfect_cube_binary_search() only accepts integers
30+
>>> perfect_cube_binary_search(0.1)
31+
Traceback (most recent call last):
32+
...
33+
TypeError: perfect_cube_binary_search() only accepts integers
3034
"""
35+
if not isinstance(n, int):
36+
raise TypeError("perfect_cube_binary_search() only accepts integers")
3137
if n < 0:
3238
n = -n
3339
left = 0
@@ -46,4 +52,4 @@ def perfect_cube_binary_search(n: int) -> bool:
4652
if __name__ == "__main__":
4753
import doctest
4854

49-
doctest.testmod()
55+
doctest.testmod()

0 commit comments

Comments
 (0)