# Forcodes.py (c) Kari Laitinen # http://www.naturalprogramming.com # 2006-04-18 File created. # 2022-12-16 Converted to Python 3. # The corresponding C++ program has the name forascii.cpp # Type char does not exist in Python. Single-character strings # represent single characters. # The format specifier %c treats an integer value as a character. # %X shows an integer in hexadecimal form. # Indentation tells the Python compiler (interpreter) which are # the internal statements of loops and if constructs. number_of_codes_on_this_line = 0 print( "\n The visible characters with codes from" \ "\n 20 to 7F (hexadecimal) are the following:\n " ) for numerical_code in range( 0x20, 0x80 ) : print( " %c %X" % ( numerical_code, numerical_code ), end="" ) number_of_codes_on_this_line += 1 if number_of_codes_on_this_line == 8 : print( "" ) # start a new line number_of_codes_on_this_line = 0 print( "\n" )