# Forcodes.py (c) 1997-2006 Kari Laitinen # http://www.naturalprogramming.com # 2006-04-18 File created. # 2006-05-30 Last modification. # 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 ), 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