We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e2a78d4 commit 878e26dCopy full SHA for 878e26d
1 file changed
conversions/ascii_to_char.py
@@ -0,0 +1,25 @@
1
+"""
2
+ascii_to_char.py
3
+----------------
4
+Converts an ASCII value (integer) to its corresponding character.
5
+
6
+Example:
7
+>>> ascii_to_char(65)
8
+'A'
9
+>>> ascii_to_char(97)
10
+'a'
11
12
13
+def ascii_to_char(ascii_value: int) -> str:
14
+ """
15
+ Convert an ASCII value to its corresponding character.
16
+ Raises ValueError if the ASCII value is not valid.
17
18
+ if not (0 <= ascii_value <= 127):
19
+ raise ValueError("ASCII value must be between 0 and 127.")
20
+ return chr(ascii_value)
21
22
23
+if __name__ == "__main__":
24
+ import doctest
25
+ doctest.testmod()
0 commit comments