Lab 5  Formatting and Files

Lab Index  Course Home Page

Task 1, Formatting Text

Write a program that does each of the following. (Test one addition at a time.)

Task 2, Reading Text Files:

Task 3 Writing Text Files

To write to a file is simpler.  Basically, one uses the following to open a file for writing
    fout = open( 'writeMe.txt', 'w' )
   
And whenever you have a string to write  <string> you use
    fout.write( <string> )
Remember that <string> must end with ‘\n’ if you want an end of line.  And you MUST finish with
    fout.close() when you are completely done writing to the file!  
Now write a program that will copy the data file from Task 1 to a new file called “backup.txt”

Open the backup file and check that you are correct.

Task 4, A Program with Text Files

Write a program to read one file, and copy it to another file with line numbers added at the beginning of each line, in the same format as Task 2.  

Show the results to a TA.


Lab Index  Course Home Page