File tree Expand file tree Collapse file tree 1 file changed +13
-6
lines changed
Expand file tree Collapse file tree 1 file changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -17,7 +17,9 @@ def binary_count_trailing_zeros(a: int) -> int:
1717 >>> binary_count_trailing_zeros(4294967296)
1818 32
1919 >>> binary_count_trailing_zeros(0)
20- 0
20+ Traceback (most recent call last):
21+ ...
22+ ValueError: Trailing zeros undefined for zero
2123 >>> binary_count_trailing_zeros(-10)
2224 Traceback (most recent call last):
2325 ...
@@ -29,16 +31,21 @@ def binary_count_trailing_zeros(a: int) -> int:
2931 >>> binary_count_trailing_zeros("0")
3032 Traceback (most recent call last):
3133 ...
32- TypeError: '<' not supported between instances of 'str' and ' int'
34+ TypeError: Input value must be a ' int' type
3335 """
36+ if not isinstance (a , int ):
37+ raise TypeError ("Input value must be a 'int' type" )
38+
3439 if a < 0 :
3540 raise ValueError ("Input value must be a positive integer" )
36- elif isinstance (a , float ):
37- raise TypeError ("Input value must be a 'int' type" )
38- return 0 if (a == 0 ) else int (log2 (a & - a ))
41+
42+ if a == 0 :
43+ raise ValueError ("Trailing zeros undefined for zero" )
44+
45+ return int (log2 (a & - a ))
3946
4047
4148if __name__ == "__main__" :
4249 import doctest
4350
44- doctest .testmod ()
51+ doctest .testmod ()
You can’t perform that action at this time.
0 commit comments