File tree 1 file changed +8
-2
lines changed
1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -9,10 +9,16 @@ def oct_to_decimal(oct_string: str) -> int:
9
9
>>> oct_to_decimal("-45")
10
10
-37
11
11
>>> oct_to_decimal("2-0Fm")
12
+ Traceback (most recent call last):
13
+ ...
12
14
ValueError: Non-octal value was passed to the function
13
15
>>> 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
15
19
>>> oct_to_decimal("19")
20
+ Traceback (most recent call last):
21
+ ...
16
22
ValueError: Non-octal value was passed to the function
17
23
"""
18
24
oct_string = str (oct_string ).strip ()
@@ -21,7 +27,7 @@ def oct_to_decimal(oct_string: str) -> int:
21
27
is_negative = oct_string [0 ] == "-"
22
28
if is_negative :
23
29
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 ):
25
31
raise ValueError ("Non-octal value was passed to the function" )
26
32
decimal_number = 0
27
33
for char in oct_string :
You can’t perform that action at this time.
0 commit comments