CS110 Introduction to Computing
Fall 2006

Lab Assignment#4

Assignment:

Problem: Write a Python program to analyze a text file to determine the number of lines, words, and letters/characters contained in the file. For example, when the program is run to process the contents of Mark Twain's Huckleberry Finn, we get the following interaction:

Enter filename: HuckleberryFinn.txt
Characters: 566016
Words: 110296
Lines: 11326

In the above sample output, the entire text of Huckleberry Finn is stored in a file called, HuckleberryFinn.txt (this file was obtained from Project Gutenberg). Visit Project Gutenberg and download at least two other texts of your chosing. You will need to strip some extraneous text out of the downloaded files before processing (see the HuckleberyFinn file for example).

What you will need to do

  1. Make sure you have read all of Chapter 4 and understand the examples and library functions presented there.
  2. Do the analysis first: clearly identify the input(s) and output(s) and the relationship(s) between them.
  3. Write the algorithm to solve the problem and then code it in Python.
  4. Make sure you do the above steps prior to entering the lab (or using your computer).
  5. Test and debug your program until it produces correct results.
  6. When done, print out the final version your your program and also a printout showing your program's output(s) on the example data above as well as the two texts you downloaded from project Gutenberg.
  7. Hand in your analysis, algorithm, and printouts of sample output (Do not include the texts!).
  8. Make a blog posting saying that you have completed the assignment and also write up any logistical or other issues/questions raised while working on this assignment. Also write about your level of confidence on the concepts learned so far.

Notes:

Add the following line to all your Python programs:

# File: <place name of your program file here>

# Date: <date created>

# Created by: <your name>

# Assignment: <place assignment number here>

Back to CS110 Course Page