# 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] infile = open(fname) wlist=[] word = infile.readline() while word: wlist.append(word[0:len(word)-1]) # strip off the last character, end of line '\n' word=infile.readline() return wlist def main(): wlist = read_words('wordsShort.txt') print 'Wlist = %s' % wlist str = raw_input('Enter a string: ') found = False k = 0 while k < len(wlist) and not found: if wlist[k] == str: found = True else: k += 1 # no k++ operator in Python if found: print "Yes, %s is a word in the list. It's in position %d." % (str, k) else: print "No, %s is not a word in the list." % (str) if __name__ == '__main__': # only matters if you're importing this module main() # Notes # ----- # This version uses a while loop and functions.