Search code examples
pythonlistdebuggingterminate

I can't figure out why it keeps terminating. it won't even work with debugger


I'm fairly new to python programming but I like to challenge myself so I made this as a stepping stone for a bigger project... the overall goal of this code is output a word from a list of words in a text file for me to translate. when I enter the english equivalent, it'll save it to a different text file. at least that's what's supposed to happen. what really happens is python opens the screen then it closes again and I can't read what's wrong. I tried importing pdb but it still just closed right away. I could really use some help fixing this problem and I had no clue where to start looking to find the answer so I'm looking to anyone out there for some greatly appreciated help. here's my code:

maxCountList = [487, 205, 327, 155]
wordList = ["nouns", "adjectives", "verbs", "various expressions"
fileListItalian = ['sostantivi.txt', 'aggettivi.txt', 'verbi.txt', 'locuzioniVarie.txt']
fileListEnglish = ['noun.txt', 'adjectives.txt', 'verbs.txt', 'variousExpressions.txt']
count1 = 0
count2 = 0
count3 = 0
count5 = 0

print "Hai! welcome to translation input!"
print "Where it is your goal to translate the word given to you"
raw_input("press any button to continue:")

while (count5 < 4):
openFile = open(fileListEnglish(count5), 'r')

for line in openFile:
    count3 + 1

if count3 == maxCountList(count5):
    count5 + 1

elif count3 == 0:
    italianFile = open(fileListItalian(count5), 'r')
    englishFile = open(fileListEnglish(count5), 'r')

    if count1 < 1:
        print "Here we go!"
        count1 + 1

    elif count1 >= 1 and <= maxCountList(count5):

        for line in italianFile:
            italianWord = line
            print italianWord
            englishWord = (raw_input("What is the english translation? >")).lower

            if len(englishWord)>= 1 and englishWord.isalpha():
                englishFile.write(englishWord + "\n")
                print englishWord + " has been written to %s." % (fileListEnglish(count5))
                englishFile.readline()
                count1 + 1

            else:
                print "Invalid. Try again"

    else:
    count2 + 1
    raw_input("That's it for %s") % (wordList(count5))
    fileListItalian(count5).close
    fileListEnglish(count5).close

elif count3 < maxCountList(count5) and count3 > 0:
    italianFile = open(fileListItalian(count5), 'r')
    englishFile = open(fileListEnglish(count5), 'r')
    count1 = count3

    if count1 < 1:
        print "Here we go!"
        count1 + 1

    elif count1 >= 1 and <= maxCountList(count5):

        for line in italianFile:
            italianWord = line
            print italianWord
            englishWord = (raw_input("What is the english translation? >")).lower

            if len(englishWord)>= 1 and englishWord.isalpha():
                englishFile.write(englishWord + "\n")
                print englishWord + " has been written to %s." % (fileListEnglish(count5))
                englishFile.readline()
                count1 + 1

            else:
                print "Invalid. Try again"

    else:
    count2 + 1
    raw_input("That's it for %s") % (wordList(count5))
    fileListItalian(count5).close
    fileListEnglish(count5).close

else:
    print "Error"
    fileListItalian(count5).close
    fileListEnglish(count5).close
count5 + 1

raw_input("All done!")

Solution

  • In addition to @Marc B's comment, specific things which are causing it to throw a SyntaxError are:

    • Missing closing bracket on line 2
    • Missing indent on line 15
    • Lines 31 and 62 both need to change to elif count1 >= 1 and count1 <= maxCountList(count5):
    • Missing indent lines 48 - 51 and 79 - 82

    After those amendments it runs.