From 878e26d96b3da881aeb310aaa085e1e25c334d00 Mon Sep 17 00:00:00 2001 From: Veda Vyasa <2400040217@kluniversity.in> Date: Thu, 30 Oct 2025 08:02:45 +0530 Subject: [PATCH 1/2] Add ascii_to_char conversion script (Fixes #13569) --- conversions/ascii_to_char.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 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..5e93325cbbcc --- /dev/null +++ b/conversions/ascii_to_char.py @@ -0,0 +1,25 @@ +""" +ascii_to_char.py +---------------- +Converts an ASCII value (integer) to its corresponding character. + +Example: +>>> ascii_to_char(65) +'A' +>>> ascii_to_char(97) +'a' +""" + +def ascii_to_char(ascii_value: int) -> str: + """ + Convert an ASCII value to its corresponding character. + Raises ValueError if the ASCII value is not valid. + """ + if not (0 <= ascii_value <= 127): + raise ValueError("ASCII value must be between 0 and 127.") + return chr(ascii_value) + + +if __name__ == "__main__": + import doctest + doctest.testmod() From 98bf3e91d573332aa7027bbc8e176fb322c5a87e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 30 Oct 2025 08:09:26 +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 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/conversions/ascii_to_char.py b/conversions/ascii_to_char.py index 5e93325cbbcc..a95c7f1f7977 100644 --- a/conversions/ascii_to_char.py +++ b/conversions/ascii_to_char.py @@ -10,6 +10,7 @@ 'a' """ + def ascii_to_char(ascii_value: int) -> str: """ Convert an ASCII value to its corresponding character. @@ -22,4 +23,5 @@ def ascii_to_char(ascii_value: int) -> str: if __name__ == "__main__": import doctest + doctest.testmod()