Skip to content

Commit 12849c6

Browse files
cybovpeRFectBeliever
authored andcommitted
Renamed octal_to_decimal to octal_to_decimal.py (TheAlgorithms#3420)
* Renamed octal_to_decimal to octal_to_decimal.py * Updated octal_to_decimal.py * modified doctests * updated octal_to_decimal.py
1 parent 18416c2 commit 12849c6

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Diff for: conversions/octal_to_decimal renamed to conversions/octal_to_decimal.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,16 @@ def oct_to_decimal(oct_string: str) -> int:
99
>>> oct_to_decimal("-45")
1010
-37
1111
>>> oct_to_decimal("2-0Fm")
12+
Traceback (most recent call last):
13+
...
1214
ValueError: Non-octal value was passed to the function
1315
>>> oct_to_decimal("")
14-
ValueError: Empty string value was passed to the function
16+
Traceback (most recent call last):
17+
...
18+
ValueError: Empty string was passed to the function
1519
>>> oct_to_decimal("19")
20+
Traceback (most recent call last):
21+
...
1622
ValueError: Non-octal value was passed to the function
1723
"""
1824
oct_string = str(oct_string).strip()
@@ -21,7 +27,7 @@ def oct_to_decimal(oct_string: str) -> int:
2127
is_negative = oct_string[0] == "-"
2228
if is_negative:
2329
oct_string = oct_string[1:]
24-
if not all(0 <= int(char) <= 7 for char in oct_string):
30+
if not oct_string.isdigit() or not all(0 <= int(char) <= 7 for char in oct_string):
2531
raise ValueError("Non-octal value was passed to the function")
2632
decimal_number = 0
2733
for char in oct_string:

0 commit comments

Comments
 (0)