HW7: Word Counter

25 points; due Fri 4/18 @ 9am.

Goals

The goal of this assignment is to work with strings, files, and definite loops.

Setup and Requirements

Create a directory named wordcount that will contain your code for this project.

This is optionally a partner assignment. If you'd like to work in a pair, please figure out who you'd like to work with via Piazza or email, and then email me once your pair is decided. Make sure to put both people's names at the top of each file. Write your code by pair-programming: code together, at the same computer, and switch off who's at the keyboard. Only one of you should ultimately submit your team's code via Moodle.

Your Assignment

There is a Unix utility called wc that analyzes a given file to determine the number of lines, words, and characters contained in it. You will write your own version of wc, as a program called wc.py. Here's a sample run (with the user's input in red):

$ python wc.py
Enter the name of the file to check: sample.txt
Lines: 10
Words: 80
Characters: 374

You will need to read the name of a file, then read that file and count words, lines and characters with your program.

Testing

You should be able to test this program on your own. Create your own text file. You should be able to manually count the number of lines, words, and characters, then see if your program gets the same answers.

If you want to double-check, use wc. Your results should be the similar. Remember that most Unix commands (wc among them) take their arguments directly on the command line. Here's an example run of wc:

$ wc sample.txt
      10      80     374 sample.txt

(Warning: wc counts non-printable characters, such as the character that represents a newline, which your version might not do. This is okay, but your results should be very similar to those of wc.)

Grading and Submission

Submit your program, wc.py, via Moodle.