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 c79034c commit 61c87e4Copy full SHA for 61c87e4
1 file changed
conversions/ascii_to_char.py
@@ -0,0 +1,31 @@
1
+"""
2
+Convert a given ASCII value to its corresponding character.
3
4
+
5
+def ascii_to_char(ascii_value: int) -> str:
6
+ """
7
+ Converts an ASCII integer value to its character equivalent.
8
9
+ >>> ascii_to_char(65)
10
+ 'A'
11
+ >>> ascii_to_char(97)
12
+ 'a'
13
+ >>> ascii_to_char(48)
14
+ '0'
15
16
+ return chr(ascii_value)
17
18
+if __name__ == "__main__":
19
+ import doctest
20
21
+ doctest.testmod()
22
23
+ input_value = input("Enter an ASCII value to convert to a character: ").strip()
24
+ try:
25
+ ascii_val = int(input_value)
26
+ if 0 <= ascii_val <= 127:
27
+ print(f"The character for ASCII value {ascii_val} is: {ascii_to_char(ascii_val)}")
28
+ else:
29
+ print("Please enter a valid ASCII value (0-127).")
30
+ except ValueError:
31
+ print("Invalid input. Please enter an integer.")
0 commit comments