From 61c87e46b32a9e9f407c92e275cb1de816804130 Mon Sep 17 00:00:00 2001 From: Thanay Bodda Date: Sun, 19 Oct 2025 10:47:09 +0300 Subject: [PATCH 1/2] Add ascii_to_char conversion script --- conversions/ascii_to_char.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 conversions/ascii_to_char.py diff --git a/conversions/ascii_to_char.py b/conversions/ascii_to_char.py new file mode 100644 index 000000000000..942f76ae60e1 --- /dev/null +++ b/conversions/ascii_to_char.py @@ -0,0 +1,31 @@ +""" +Convert a given ASCII value to its corresponding character. +""" + +def ascii_to_char(ascii_value: int) -> str: + """ + Converts an ASCII integer value to its character equivalent. + + >>> ascii_to_char(65) + 'A' + >>> ascii_to_char(97) + 'a' + >>> ascii_to_char(48) + '0' + """ + return chr(ascii_value) + +if __name__ == "__main__": + import doctest + + doctest.testmod() + + input_value = input("Enter an ASCII value to convert to a character: ").strip() + try: + ascii_val = int(input_value) + if 0 <= ascii_val <= 127: + print(f"The character for ASCII value {ascii_val} is: {ascii_to_char(ascii_val)}") + else: + print("Please enter a valid ASCII value (0-127).") + except ValueError: + print("Invalid input. Please enter an integer.") \ No newline at end of file From 0ca904d49d79f7a408cddb2d40558fdab888a649 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 19 Oct 2025 08:01:02 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- conversions/ascii_to_char.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/conversions/ascii_to_char.py b/conversions/ascii_to_char.py index 942f76ae60e1..3d8dca5f0f3d 100644 --- a/conversions/ascii_to_char.py +++ b/conversions/ascii_to_char.py @@ -2,6 +2,7 @@ Convert a given ASCII value to its corresponding character. """ + def ascii_to_char(ascii_value: int) -> str: """ Converts an ASCII integer value to its character equivalent. @@ -15,6 +16,7 @@ def ascii_to_char(ascii_value: int) -> str: """ return chr(ascii_value) + if __name__ == "__main__": import doctest @@ -24,8 +26,10 @@ def ascii_to_char(ascii_value: int) -> str: try: ascii_val = int(input_value) if 0 <= ascii_val <= 127: - print(f"The character for ASCII value {ascii_val} is: {ascii_to_char(ascii_val)}") + print( + f"The character for ASCII value {ascii_val} is: {ascii_to_char(ascii_val)}" + ) else: print("Please enter a valid ASCII value (0-127).") except ValueError: - print("Invalid input. Please enter an integer.") \ No newline at end of file + print("Invalid input. Please enter an integer.")