Assignment 3 Part 4 (submitted by Scott on Feb 12, 20:13)

Beautiful Code
Ka-Ping Yee

AUTHORS:   Adam   Calvin   Chris   David   Derek   Hunter   Jacob   Jason   Jun   Karl   Kevin   Michael   Morgan   Nadia   Nerissa   Omair   Peter   Peterson   Ping   Richard   Scott   Thanh   Varun

Download this file.

COMMENTS

Feb 16, 17:31 - Hunter: What's nice about this module is that it pretty much works without too many changes -- some things had to be done to make sure the file read properly, but nothing else too great was needed. Of course, it would be a lot faster if it used a dictionary data type, instead of going through the file every time a word was looked up, but this isn't critical to the functionality of the program, just to its efficiency.

Feb 17, 20:26 - Scott: I agree. This isn't a very efficient module. It was the only one that Varun used though, so I implimented it.

Feb 23, 16:26 - Ping: You're allowed to put stuff outside the functions, so the module can initialize the dictionary when it first loads.

Please log in if you would like to add comments.

   

  1 def test_word(word):
  2     '''searches a dictionary file for existance of word given returning 0 if
  3     it's not found and 1 if it is.  An error message is printed if no
  4     dictionary file can be found'''
  5     try:
  6         dictionary = open("dict.txt", r)
  7         #assume dict.txt is in same directory#
  8     except:
  9         print 'Unable to find dict.txt in this directory'
 10     correct_words = dictionary.split()
 11     if word in correct_words:
 12         correctness = 1
 13     else: correctness = 0
 14     return correctness