mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-02-25 18:38: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
f1c6a65593
commit
c9e7bf6e45
@ -1,62 +1,62 @@
|
||||
def octal_to_binary(octal:str) -> str:
|
||||
def octal_to_binary(octal: str) -> str:
|
||||
"""
|
||||
Convert an octal value to its binary equivalent
|
||||
Convert an octal value to its binary equivalent
|
||||
|
||||
>>> octal_to_binary("")
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValueError: Empty string was passed to the function
|
||||
>>> octal_to_binary("-")
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValueError: Non-octal value was passed to the function
|
||||
>>> octal_to_binary("e")
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValueError: Non-octal value was passed to the function
|
||||
>>> octal_to_binary(8)
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValueError: Non-octal value was passed to the function
|
||||
>>> octal_to_binary("-e")
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValueError: Non-octal value was passed to the function
|
||||
>>> octal_to_binary("-8")
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValueError: Non-octal value was passed to the function
|
||||
>>> octal_to_binary("1")
|
||||
'0b1'
|
||||
>>> octal_to_binary("-1")
|
||||
'-0b1'
|
||||
>>> octal_to_binary("12")
|
||||
'0b1010'
|
||||
>>> octal_to_binary(" 12 ")
|
||||
'0b1010'
|
||||
>>> octal_to_binary("-45")
|
||||
'-0b100101'
|
||||
>>> octal_to_binary("-")
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValueError: Non-octal value was passed to the function
|
||||
>>> octal_to_binary("0")
|
||||
'0b0'
|
||||
>>> octal_to_binary("-4055")
|
||||
'-0b100000101101'
|
||||
>>> octal_to_binary("2-0Fm")
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValueError: Non-octal value was passed to the function
|
||||
>>> octal_to_binary("")
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValueError: Empty string was passed to the function
|
||||
>>> octal_to_binary("19")
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValueError: Non-octal value was passed to the function
|
||||
"""
|
||||
>>> octal_to_binary("")
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValueError: Empty string was passed to the function
|
||||
>>> octal_to_binary("-")
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValueError: Non-octal value was passed to the function
|
||||
>>> octal_to_binary("e")
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValueError: Non-octal value was passed to the function
|
||||
>>> octal_to_binary(8)
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValueError: Non-octal value was passed to the function
|
||||
>>> octal_to_binary("-e")
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValueError: Non-octal value was passed to the function
|
||||
>>> octal_to_binary("-8")
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValueError: Non-octal value was passed to the function
|
||||
>>> octal_to_binary("1")
|
||||
'0b1'
|
||||
>>> octal_to_binary("-1")
|
||||
'-0b1'
|
||||
>>> octal_to_binary("12")
|
||||
'0b1010'
|
||||
>>> octal_to_binary(" 12 ")
|
||||
'0b1010'
|
||||
>>> octal_to_binary("-45")
|
||||
'-0b100101'
|
||||
>>> octal_to_binary("-")
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValueError: Non-octal value was passed to the function
|
||||
>>> octal_to_binary("0")
|
||||
'0b0'
|
||||
>>> octal_to_binary("-4055")
|
||||
'-0b100000101101'
|
||||
>>> octal_to_binary("2-0Fm")
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValueError: Non-octal value was passed to the function
|
||||
>>> octal_to_binary("")
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValueError: Empty string was passed to the function
|
||||
>>> octal_to_binary("19")
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValueError: Non-octal value was passed to the function
|
||||
"""
|
||||
|
||||
oct_string = str(octal).strip()
|
||||
if not oct_string:
|
||||
@ -91,6 +91,8 @@ def octal_to_binary(octal:str) -> str:
|
||||
|
||||
return "0b" + "".join(str(e) for e in binary)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
from doctest import testmod
|
||||
|
||||
testmod()
|
||||
|
Loading…
x
Reference in New Issue
Block a user