mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-23 13:01:08 +00:00
use format to remove '0b' (#11307)
* use format to remove '0b' * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix: error message for float input --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
723cf9c428
commit
edee8e644b
|
@ -26,7 +26,7 @@ def binary_and(a: int, b: int) -> str:
|
|||
>>> binary_and(0, 1.1)
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
TypeError: 'float' object cannot be interpreted as an integer
|
||||
ValueError: Unknown format code 'b' for object of type 'float'
|
||||
>>> binary_and("0", "1")
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
|
@ -35,8 +35,8 @@ def binary_and(a: int, b: int) -> str:
|
|||
if a < 0 or b < 0:
|
||||
raise ValueError("the value of both inputs must be positive")
|
||||
|
||||
a_binary = str(bin(a))[2:] # remove the leading "0b"
|
||||
b_binary = str(bin(b))[2:] # remove the leading "0b"
|
||||
a_binary = format(a, "b")
|
||||
b_binary = format(b, "b")
|
||||
|
||||
max_len = max(len(a_binary), len(b_binary))
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user