0

我对 python 编程相当陌生,但我喜欢挑战自己,所以我把它作为一个更大项目的垫脚石......这段代码的总体目标是从文本文件中的单词列表中为我输出一个单词翻译。当我输入等效英文时,它会将其保存到不同的文本文件中。至少这是应该发生的。真正发生的是python打开屏幕然后它再次关闭,我看不出有什么问题。我尝试导入 pdb,但它仍然立即关闭。我真的可以使用一些帮助来解决这个问题,但我不知道从哪里开始寻找答案,所以我正在向那里的任何人寻求一些非常感谢的帮助。这是我的代码:

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!")
4

1 回答 1

2

除了@Marc B 的评论之外,导致它抛出 SyntaxError 的具体事情是:

  • 第 2 行缺少右括号
  • 第 15 行缺少缩进
  • 第 31 行和第 62 行都需要更改为elif count1 >= 1 and count1 <= maxCountList(count5):
  • 缺少缩进行 48 - 51 和 79 - 82

在这些修改之后,它运行。

于 2013-04-28T01:59:35.843 回答