<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">I made this program but it says that there is an error and I have a hard time trying to solve the problem with program. Here is the program:<br><br><br>#this reads all of the words in the file into a list<br>infile = open('/afs/cats/courses/cmps012a-cm/pa1/wordList.txt')<br>wdcount = int(infile.readline()) #first item is count of all the words<br>word_list = infile.readlines()<br><br>#print them out from the internal list<br>i = 0<br>while i < wdcount:<br> print word_list[i],<br> i = i + 1<br><br>#map of alphabet to prime numbers with respect to frecuency<br>#more frequent the letter the smaller the assigment prime<br>letter_to_prime = {<br> 'a':7,<br> 'b':59,<br> 'c':29,<br> 'd':31,<br> 'e':2,<br>
'f':67,<br> 'g':41,<br> 'h':53,<br> 'i':3,<br> 'j':97,<br> 'k':73,<br> 'l':23,<br> 'm':47,<br> 'n':13,<br> 'o':19,<br> 'p':43,<br> 'q':101,<br> 'r':11,<br> 's':5,<br> 't':17,<br> 'u':37,<br> 'v':71,<br> 'w':79,<br> 'x':89,<br> 'y':61,<br> 'z':83},<br><br>j = 0<br>while j < wdcount:<br> print word_list [j],<br> prod = 1<br> i = 0<br> while i < len(word_list[j])-2:<br> prod = prod * letter_to_prime[word_list[j] [i]:<br> i = i +
1<br> print prod (right here is where it says that there's an error I try to fix it )<br> j = j =1<br> <br># code that will be compared will be a histogram type code with frequency<br># characters<br>def code(w):<br> hist = []<br> chars = list(w) <br> chars.sort() <br> for letter in chars: <br> if not letter in hist: # when the letter is not already in hist, <br> hist.extend([letter, str(w.count(letter))]) # its added to hist along with its freq.<br> else:
<br> continue<br> coding = "".join(hist) # then they are joined as one string<br> return coding<br><br><br><br><br># new list is made with words in word_list followed by its code<br>for word in word_list:<br> wordList.append(word) <br> wordList.append(code(word[:(len(word)-2)])) <br><br><br>while True:<br> word1 = raw_input('Enter word:') <br> word = word1.lower() <br> sig = code(word) <br> i = 1 <br> if sig in wordList: <br> print "Anagrams:"<br> while i <= len(wordList): # when the sig of the inputed word is in the word list, <br> if sig ==
wordList[i]:<br> print wordList[i-1] # the corresponding words are printed<br> i += 2 # then adds two because codes are every other entry<br> else:<br> print "No anagrams"<br> choice = raw_input("Continue? (yes/no)")<br> if choice == 'y' or choice == 'yes':<br> continue<br> else:<br> break<br>I don't know how to figure out the error since the only message that I get is that "there's an error: invalid syntax"<br><br></td></tr></table><br>