mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-23 21:11:08 +00:00
Renamed octal_to_decimal to octal_to_decimal.py (#3420)
* Renamed octal_to_decimal to octal_to_decimal.py * Updated octal_to_decimal.py * modified doctests * updated octal_to_decimal.py
This commit is contained in:
parent
03e7f37329
commit
49d0c41905
|
@ -9,10 +9,16 @@ def oct_to_decimal(oct_string: str) -> int:
|
||||||
>>> oct_to_decimal("-45")
|
>>> oct_to_decimal("-45")
|
||||||
-37
|
-37
|
||||||
>>> oct_to_decimal("2-0Fm")
|
>>> oct_to_decimal("2-0Fm")
|
||||||
|
Traceback (most recent call last):
|
||||||
|
...
|
||||||
ValueError: Non-octal value was passed to the function
|
ValueError: Non-octal value was passed to the function
|
||||||
>>> oct_to_decimal("")
|
>>> oct_to_decimal("")
|
||||||
ValueError: Empty string value was passed to the function
|
Traceback (most recent call last):
|
||||||
|
...
|
||||||
|
ValueError: Empty string was passed to the function
|
||||||
>>> oct_to_decimal("19")
|
>>> oct_to_decimal("19")
|
||||||
|
Traceback (most recent call last):
|
||||||
|
...
|
||||||
ValueError: Non-octal value was passed to the function
|
ValueError: Non-octal value was passed to the function
|
||||||
"""
|
"""
|
||||||
oct_string = str(oct_string).strip()
|
oct_string = str(oct_string).strip()
|
||||||
|
@ -21,7 +27,7 @@ def oct_to_decimal(oct_string: str) -> int:
|
||||||
is_negative = oct_string[0] == "-"
|
is_negative = oct_string[0] == "-"
|
||||||
if is_negative:
|
if is_negative:
|
||||||
oct_string = oct_string[1:]
|
oct_string = oct_string[1:]
|
||||||
if not all(0 <= int(char) <= 7 for char in oct_string):
|
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")
|
raise ValueError("Non-octal value was passed to the function")
|
||||||
decimal_number = 0
|
decimal_number = 0
|
||||||
for char in oct_string:
|
for char in oct_string:
|
Loading…
Reference in New Issue
Block a user