Skip to content

Commit 43c22b3

Browse files
authored
Update error messages for binary_and function
1 parent 37d41a7 commit 43c22b3

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

bit_manipulation/binary_and_operator.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,25 @@ def binary_and(a: int, b: int) -> str:
2222
>>> binary_and(0, -1)
2323
Traceback (most recent call last):
2424
...
25-
ValueError: the value of both inputs must be positive
25+
ValueError: the value of both inputs must be non-negative
2626
>>> binary_and(0, 1.1)
2727
Traceback (most recent call last):
2828
...
29-
ValueError: Unknown format code 'b' for object of type 'float'
29+
TypeError: both inputs must be integers
3030
>>> binary_and("0", "1")
3131
Traceback (most recent call last):
3232
...
33-
TypeError: '<' not supported between instances of 'str' and 'int'
33+
TypeError: both inputs must be integers
34+
>>> binary_and(10, "1")
35+
Traceback (most recent call last):
36+
...
37+
TypeError: both inputs must be integers
3438
"""
39+
if type(a) is not int or type(b) is not int:
40+
raise TypeError("both inputs must be integers")
41+
3542
if a < 0 or b < 0:
36-
raise ValueError("the value of both inputs must be positive")
43+
raise ValueError("the value of both inputs must be non-negative")
3744

3845
a_binary = format(a, "b")
3946
b_binary = format(b, "b")

0 commit comments

Comments
 (0)