# Spell checker, Version 1.0 # Input: Dictionary of six-letter words and a string entered by the user # Process: determine if the user's string is a word in the dictionary # Output: Indicate YES or NO def read_words(fname): infile = open(fname) temp = infile.read() #temporary variable, dynamic type is string infile.close() return temp.split('\n')[:-1] def main(): wlist = read_words('words.txt') print 'wlist = %s' % wlist str = raw_input('Enter a string (use "*quit* to stop): ') done = False if str == "*quit*": done = True while not done: flag = False k = 0 while k < len(wlist): if wlist[k] == str: flag = True break k += 1 # no k++ operator in Python else: print "No, %s is not a word in the list." % (str) #return if flag: print "Yes, %s is a word in the list. It's in slot %d." % (str, k) print str = raw_input('Enter a string (use "*quit* to stop): ') if str == "*quit*": done = True print "Good-bye" if __name__ == '__main__': # only matters if you're importing this module main() # Notes # ----- # This version uses a while-else loop, but be careful of spaghetti code.