|
1 |
| -def count_one_bits(number: int) -> int: |
| 1 | +def get_set_bits_count(number: int) -> int: |
2 | 2 | """
|
3 |
| - Take in an 32 bit integer, count the number of one bits, |
4 |
| - return the number of one bits |
5 |
| - result of a count_one_bits and operation on the integer provided. |
6 |
| - >>> count_one_bits(25) |
| 3 | + Count the number of set bits in a 32 bit integer |
| 4 | + >>> get_set_bits_count(25) |
7 | 5 | 3
|
8 |
| - >>> count_one_bits(37) |
| 6 | + >>> get_set_bits_count(37) |
9 | 7 | 3
|
10 |
| - >>> count_one_bits(21) |
| 8 | + >>> get_set_bits_count(21) |
11 | 9 | 3
|
12 |
| - >>> count_one_bits(58) |
| 10 | + >>> get_set_bits_count(58) |
13 | 11 | 4
|
14 |
| - >>> count_one_bits(0) |
| 12 | + >>> get_set_bits_count(0) |
15 | 13 | 0
|
16 |
| - >>> count_one_bits(256) |
| 14 | + >>> get_set_bits_count(256) |
17 | 15 | 1
|
18 |
| - >>> count_one_bits(-1) |
| 16 | + >>> get_set_bits_count(-1) |
19 | 17 | Traceback (most recent call last):
|
20 | 18 | ...
|
21 | 19 | ValueError: the value of input must be positive
|
22 |
| - >>> count_one_bits(1.1) |
23 |
| - Traceback (most recent call last): |
24 |
| - ... |
25 |
| - TypeError: Input value must be a 'int' type |
26 |
| - >>> count_one_bits("0") |
27 |
| - Traceback (most recent call last): |
28 |
| - ... |
29 |
| - TypeError: '<' not supported between instances of 'str' and 'int' |
30 | 20 | """
|
31 | 21 | if number < 0:
|
32 | 22 | raise ValueError("the value of input must be positive")
|
33 |
| - elif isinstance(number, float): |
34 |
| - raise TypeError("Input value must be a 'int' type") |
35 |
| - elif isinstance(number, str): |
36 |
| - raise TypeError("'<' not supported between instances of 'str' and 'int'") |
37 | 23 | result = 0
|
38 | 24 | while number:
|
39 | 25 | if number % 2 == 1:
|
|
0 commit comments