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 に答える