# Author: James Tam # Version: March 23 2010 # On a line-by-line basis the program reads from a file called "input.txt". # Each character of the line will be prefaced by an index number and then displayed # onscreen all on one line. # Open file for reading, confirm file with user. inputFile = open ("input.txt", "r") # While we haven't read past the end of the file continue reading from # it. for line in inputFile: i = 0 # The variable ch will start at the first character in the string "line" and # iterate through the string up to and including the last character. for ch in line: # Each character in the string "line" is given an index value depending # upon it's position (first is zero, second is one etc.) The index and the # character are displayed onscreen. print i, ch, # Increase the index in anticipation of reading the next character from line. i = i + 1 print # Finished writing to file, provide feedback to user and close file. print "Completed reading of file input.txt" inputFile.close()