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:
Mikail Farid 2020-11-23 07:11:28 +01:00 committed by GitHub
parent 03e7f37329
commit 49d0c41905
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -9,10 +9,16 @@ def oct_to_decimal(oct_string: str) -> int:
>>> oct_to_decimal("-45")
-37
>>> oct_to_decimal("2-0Fm")
Traceback (most recent call last):
...
ValueError: Non-octal value was passed to the function
>>> 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")
Traceback (most recent call last):
...
ValueError: Non-octal value was passed to the function
"""
oct_string = str(oct_string).strip()
@ -21,7 +27,7 @@ def oct_to_decimal(oct_string: str) -> int:
is_negative = oct_string[0] == "-"
if is_negative:
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")
decimal_number = 0
for char in oct_string: