CS 111: Introduction to Computer Science

A spell-checker

Due by 8:30AM Monday, April 27.

Hand in as: spellchecker.py

You may work with one partner on this assignment. In fact, I recommend it.

The program

For this assignment, you will write a simple spell-checking program.

Once it is complete, here is what your program should do:

No individual step in this program is complex beyond the sorts of things you have already written in Python. However, the program requires several steps, and thus you will need to plan your development carefully. We will discuss several aspects of this program in class on Wednesday, so spend some time thinking about the program beforehand.

Here's a brief outline of steps your program could take to complete the spell-checking task.

  1. Read the names of the two files from the command line. (See commandline.py for a sample of how this works.)
  2. Open the file containing the acceptable words, and read those words into a Python list. Close the file. You may assume that this file consists of exactly one word per line, with no punctuation. A good example of such a file is sowpods.txt (see this description of SOWPODS if you're interested in where this list comes from).
  3. Open the file you want to spell-check. Read it one line at a time, keeping a counter variable representing the current line number.
  4. For each line, split the line into words and remove the punctuation from each word.
  5. For each word, scan through the list of acceptable words to see if you can find the word you are looking for. If you find the word in the acceptable words list, then the word is correctly spelled. If you don't, then you should print "Line N: WORD", where N is the current line number and WORD is the misspelled word.
  6. Close the file you're spell-checking.

You can write the program one step at a time, testing each step after you have completed it. For example, after you have written code to perform step 1 above, you can simply print out the name of the word-list file and the name of the file-to-be-checked to make sure your program is getting the correct names. Then, after you have written the code for step 2, you can print out the list of acceptable words (for this test, you may wish to use a shorter word list than sowpods.txt). This sort of step-by-step "write a little code, then test it" approach is called "incremental development," and is a powerful way to gradually build complex systems out of simple pieces. More on this in class.

Have fun, and bring your questions to class, office hours, and Reid's prefect sessions.