Skip to content

Renamed octal_to_decimal to octal_to_decimal.py #3420

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 23, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions conversions/octal_to_decimal → conversions/octal_to_decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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:
Expand Down