jessica cruz jessica06cruz at yahoo.com
Mon Mar 9 19:38:19 CET 2009

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:

#this reads all of the words in the file into a list
infile = open('/afs/cats/courses/cmps012a-cm/pa1/wordList.txt')
wdcount = int(infile.readline()) #first item is count of all the words
word_list = infile.readlines()

#print them out from the internal list
i = 0
while i < wdcount:
    print word_list[i],
    i = i + 1

#map of alphabet to prime numbers with respect to frecuency
#more frequent the letter the smaller the assigment prime
letter_to_prime = {

j = 0
while j < wdcount:
    print word_list [j],
    prod = 1
    i = 0
    while i < len(word_list[j])-2:
        prod = prod * letter_to_prime[word_list[j] [i]:
        i = i + 1
    print prod (right here is where it says that there's an error I try to fix it )
    j = j =1
# code that will be compared will be a histogram type code with frequency
# characters
def code(w):
    hist = []
    chars = list(w) 
    for letter in chars: 
        if not letter in hist:  # when the letter is not already in hist, 
            hist.extend([letter, str(w.count(letter))])  # its added to hist along with its freq.
    coding = "".join(hist) # then they are joined as one string
    return coding

# new list is made with words in word_list followed by its code
for word in  word_list:

while True:
    word1 = raw_input('Enter word:') 
    word = word1.lower() 
    sig = code(word) 
    i = 1 
    if sig in wordList: 
        print "Anagrams:"
        while i <= len(wordList):  # when the sig of the inputed word is in the word list, 
            if sig == wordList[i]:
                print wordList[i-1]  # the corresponding words are printed
            i += 2 # then adds two because codes are every other entry
        print "No anagrams"
    choice = raw_input("Continue? (yes/no)")
    if choice == 'y' or choice == 'yes':
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"

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090309/f093e484/attachment.htm>

More information about the Tutor mailing list