Skip to content
Open
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: 9 additions & 1 deletion conversions/binary_to_decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ def bin_to_decimal(bin_string: str) -> int:
Traceback (most recent call last):
...
ValueError: Empty string was passed to the function
>>> bin_to_decimal("-")
Traceback (most recent call last):
...
ValueError: Non-binary value was passed to the function
>>> bin_to_decimal(" - ")
Traceback (most recent call last):
...
ValueError: Non-binary value was passed to the function
>>> bin_to_decimal("39")
Traceback (most recent call last):
...
Expand All @@ -29,7 +37,7 @@ def bin_to_decimal(bin_string: str) -> int:
is_negative = bin_string[0] == "-"
if is_negative:
bin_string = bin_string[1:]
if not all(char in "01" for char in bin_string):
if not bin_string or not all(char in "01" for char in bin_string):
raise ValueError("Non-binary value was passed to the function")
decimal_number = 0
for char in bin_string:
Expand Down
Loading