Home CPSC 110

Lab 7: Spell Check



To gain experience with using lists and files.



For this lab, you will write a program that performs spell checking on words the user can enter in.

The way this will work is you will read in a file containing almost 100,000 English words and store them in a list. This wouldn't be feasible without a list variable! Once you have the list of all valid words, you can ask the user to enter words they wish to check. If their input is in the list, then it's spelt correctly. Otherwise, we tell them it's spelt wrong.



  1. Start by downloading the dictionary file words.txt. Put it into the same folder on your computer where you will write your program. If it's not in the same folder, your program won't be able to find it!
  2. Next, open the file with code like this:
    file = open("words.txt", "r")
  3. Then, we can read all of the data into a string variable like this:
    data = file.read()
    This will create a very long string variable containing all of the words in the file.
  4. Next, split this string into a list of words as discussed in class. You should now have a list containing all the English words.
  5. Now create a while loop to read the user input. It should let the user enter as many words as they want until they enter "quit".
  6. Inside the loop, after asking the user for their word, heck if their word is in the list or not. If it isn't, then you should print a message saying it's not spelt correctly.


Example Run

Below is an example run of how this program should work:

Enter a word: here
Enter a word: are
Enter a word: soem
soem is spelled wrong
Enter a word: words
Enter a word: tetsing
tetsing is spelled wrong
Enter a word: this
Enter a word: pogram
pogram is spelled wrong
Enter a word: quit



When you are finished, please submit the .py file for the lab on Canvas. To do so, you'll need to navigate to where you saved the file on your computer.

Copyright © 2022 Ian Finlayson | Licensed under a Attribution-NonCommercial 4.0 International License.