2013-04-28 32 views
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!") 
+0

我認爲你只是雙擊Windows中的.py文件或其他東西?不要這樣做。打開一個適當的命令提示符並嘗試從那裏運行腳本。該窗口將保持打開並顯示任何輸出/錯誤消息。 – 2013-04-28 00:51:20

+0

這是我遇到的問題之一,因爲我正在使用公用計算機上的便攜式硬盤。我無法使用命令的一半時間,當我這樣做時,我必須鍵入Python和我的程序的完整路徑 – theDr34mer 2013-04-30 18:28:27

回答

1

除了@Marc B的評論,具體的事情這是導致它拋出一個SyntaxError是:

  • 缺少第2行
  • 缺少縮進的閉架第15行
  • 第31行和第62行都需要更改爲elif count1 >= 1 and count1 <= maxCountList(count5):
  • 缺少縮進行48 - 51和79 - 82

經過這些修改後,它運行。

+0

謝謝你的幫助。現在一切都變好了。我只需要弄清楚如何打開它。我正在關閉一個便攜式硬盤驅動器,我無法很容易地運行它,但這完全是一個不同的問題 – theDr34mer 2013-04-30 18:25:17

相關問題