我对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!")
答案 0 :(得分:2)
除了@Marc B的评论之外,导致它抛出SyntaxError的具体事情是:
elif count1 >= 1 and count1 <= maxCountList(count5):
经过这些修改之后。