mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-02-25 10:28:39 +00:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
b8b3b8c593
commit
eedc5935ad
@ -1,4 +1,4 @@
|
||||
def octal_to_binary(octal:str) -> str:
|
||||
def octal_to_binary(octal: str) -> str:
|
||||
"""
|
||||
Convert an octal value to its binary equivalent
|
||||
>>> octal_to_binary("")
|
||||
@ -59,16 +59,19 @@ def octal_to_binary(octal:str) -> str:
|
||||
oct_string = str(octal).strip()
|
||||
if not oct_string:
|
||||
raise ValueError("Empty string was passed to the function")
|
||||
is_negative = oct_string.startswith('-')
|
||||
is_negative = oct_string.startswith("-")
|
||||
if is_negative:
|
||||
oct_string = oct_string[1:]
|
||||
binary_num = '-0b'
|
||||
binary_num = "-0b"
|
||||
else:
|
||||
binary_num = '0b'
|
||||
binary_num = "0b"
|
||||
if not oct_string.isdigit() or not all(0 <= int(char) <= 7 for char in oct_string):
|
||||
raise ValueError("Non-octal value was passed to the function")
|
||||
binary_num += str(bin(int(oct_string, 8)))[2:]
|
||||
return binary_num
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
from doctest import testmod
|
||||
|
||||
testmod()
|
||||
|
Loading…
x
Reference in New Issue
Block a user