From def19a1d462787ece178eacd09160850cebdb778 Mon Sep 17 00:00:00 2001 From: L4XB Date: Fri, 23 Oct 2026 06:09:19 +0200 Subject: [PATCH] fix: return 0x0 from octal_to_hex("0") The loop builds no hex digit for 0, so the function returned '0x'. The check in the module's own __main__ block expects '0x' + hex(int(num, 8))[2:].upper(), which is '0x0'. --- conversions/octal_to_hexadecimal.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/conversions/octal_to_hexadecimal.py b/conversions/octal_to_hexadecimal.py index 0615d79b5c53..80f94cf765a5 100644 --- a/conversions/octal_to_hexadecimal.py +++ b/conversions/octal_to_hexadecimal.py @@ -7,6 +7,8 @@ def octal_to_hex(octal: str) -> str: '0x40' >>> octal_to_hex("235") '0x9D' + >>> octal_to_hex("0") + '0x0' >>> octal_to_hex(17) Traceback (most recent call last): ... @@ -42,7 +44,7 @@ def octal_to_hex(octal: str) -> str: revhex += hex_char[decimal & 15] decimal >>= 4 - return "0x" + revhex[::-1] + return "0x" + (revhex[::-1] or "0") if __name__ == "__main__":