File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 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." )
You can’t perform that action at this time.
0 commit comments