From e3e2f2388b3382e0b3bb9ab13a107fe0b2eef004 Mon Sep 17 00:00:00 2001 From: cybov Date: Sat, 17 Oct 2020 07:09:22 +0100 Subject: [PATCH 1/4] Renamed octal_to_decimal to octal_to_decimal.py --- conversions/{octal_to_decimal => octal_to_decimal.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename conversions/{octal_to_decimal => octal_to_decimal.py} (100%) diff --git a/conversions/octal_to_decimal b/conversions/octal_to_decimal.py similarity index 100% rename from conversions/octal_to_decimal rename to conversions/octal_to_decimal.py From a280191543ed43d0af6d0718d3bd51d2709c9d9f Mon Sep 17 00:00:00 2001 From: cybov Date: Sat, 17 Oct 2020 07:35:55 +0100 Subject: [PATCH 2/4] Updated octal_to_decimal.py --- conversions/octal_to_decimal.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/conversions/octal_to_decimal.py b/conversions/octal_to_decimal.py index a5b027e3ae8d..e7aec570a6df 100644 --- a/conversions/octal_to_decimal.py +++ b/conversions/octal_to_decimal.py @@ -21,7 +21,9 @@ 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.isdecimal() 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: From d20f6c147e1c2cf8890900e512eb71bd0f53b2dc Mon Sep 17 00:00:00 2001 From: cybov Date: Sat, 17 Oct 2020 07:48:59 +0100 Subject: [PATCH 3/4] modified doctests --- conversions/octal_to_decimal.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/conversions/octal_to_decimal.py b/conversions/octal_to_decimal.py index e7aec570a6df..853deaf4311a 100644 --- a/conversions/octal_to_decimal.py +++ b/conversions/octal_to_decimal.py @@ -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() From ad0047afed9b404f33188809bd3500d280f24535 Mon Sep 17 00:00:00 2001 From: cybov Date: Sat, 17 Oct 2020 08:10:55 +0100 Subject: [PATCH 4/4] updated octal_to_decimal.py --- conversions/octal_to_decimal.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/conversions/octal_to_decimal.py b/conversions/octal_to_decimal.py index 853deaf4311a..5a7373fef7e3 100644 --- a/conversions/octal_to_decimal.py +++ b/conversions/octal_to_decimal.py @@ -27,9 +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 oct_string.isdecimal() or 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: