mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-23 21:11:08 +00:00
Fix argument validation for count_1s_brian_kernighan_method (#7994)
* Fix argument validation for count_1s_brian_kernighan_method * updating DIRECTORY.md Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
parent
f01a1af1df
commit
a25c53e8b0
|
@ -571,6 +571,7 @@
|
||||||
* [Largest Subarray Sum](maths/largest_subarray_sum.py)
|
* [Largest Subarray Sum](maths/largest_subarray_sum.py)
|
||||||
* [Least Common Multiple](maths/least_common_multiple.py)
|
* [Least Common Multiple](maths/least_common_multiple.py)
|
||||||
* [Line Length](maths/line_length.py)
|
* [Line Length](maths/line_length.py)
|
||||||
|
* [Liouville Lambda](maths/liouville_lambda.py)
|
||||||
* [Lucas Lehmer Primality Test](maths/lucas_lehmer_primality_test.py)
|
* [Lucas Lehmer Primality Test](maths/lucas_lehmer_primality_test.py)
|
||||||
* [Lucas Series](maths/lucas_series.py)
|
* [Lucas Series](maths/lucas_series.py)
|
||||||
* [Maclaurin Series](maths/maclaurin_series.py)
|
* [Maclaurin Series](maths/maclaurin_series.py)
|
||||||
|
|
|
@ -17,16 +17,19 @@ def get_1s_count(number: int) -> int:
|
||||||
>>> get_1s_count(-1)
|
>>> get_1s_count(-1)
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
...
|
...
|
||||||
ValueError: the value of input must be positive
|
ValueError: Input must be a non-negative integer
|
||||||
>>> get_1s_count(0.8)
|
>>> get_1s_count(0.8)
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
...
|
...
|
||||||
TypeError: Input value must be an 'int' type
|
ValueError: Input must be a non-negative integer
|
||||||
|
>>> get_1s_count("25")
|
||||||
|
Traceback (most recent call last):
|
||||||
|
...
|
||||||
|
ValueError: Input must be a non-negative integer
|
||||||
"""
|
"""
|
||||||
if number < 0:
|
if not isinstance(number, int) or number < 0:
|
||||||
raise ValueError("the value of input must be positive")
|
raise ValueError("Input must be a non-negative integer")
|
||||||
elif isinstance(number, float):
|
|
||||||
raise TypeError("Input value must be an 'int' type")
|
|
||||||
count = 0
|
count = 0
|
||||||
while number:
|
while number:
|
||||||
# This way we arrive at next set bit (next 1) instead of looping
|
# This way we arrive at next set bit (next 1) instead of looping
|
||||||
|
|
Loading…
Reference in New Issue
Block a user