2017-01-22 82 views
-1

我複製並粘貼了一些代碼,從如何自動化無聊的東西,這個消息不斷來。我試圖改變空間或標籤的數量,並用崇高的文字嘗試各種各樣的東西。請幫忙。此消息不斷出現,我不知道該怎麼辦

生成35個測驗文件。

for quizNum in range(35): 

    # Create the quiz and answer key files. 
    quizFile = open('capitalsquiz%s.txt' % (quizNum + 1), 'w') 
    answerKeyFile = open('capitalsquiz_answers%s.txt' % (quizNum + 1), 'w') 

    # Write out the header for the quiz. 
quizFile.write('Name:\n\nDate:\n\nPeriod:\n\n') 
    quizFile.write((' ' * 20) + 'State Capitals Quiz (Form %s)' % (quizNum + 1)) 
    quizFile.write('\n\n') 


     # TODO: Shuffle the order of the states. 
       states = list(capitals.keys()) 
      random.shuffle(states) 



     # TODO: Loop through all 50 states, making a question for each. 
      for questionNum in range(50): 

       # Get right and wrong answers. 
     correctAnswer = capitals[states[questionNum]] 
      wrongAnswers = list(capitals.values()) 
      del wrongAnswers[wrongAnswers.index(correctAnswer)] 
      wrongAnswers = random.sample(wrongAnswers, 3) 
      answerOptions = wrongAnswers + [correctAnswer] 
     random.shuffle(answerOptions) 
+2

該示例有縮進錯誤,您需要修復。你還沒有提到問題是什麼! – tdelaney

+0

這是什麼*「消息」*? – shash678

+0

您尚未解釋問題或提出問題。您提到*此消息不斷顯示*,但您不必費心告訴我們顯示的消息是什麼,儘管它在屏幕上顯示爲**。你要求我們提供**免費幫助**來解決**你的問題**,但是你不能爲實際提供給我們需要的細節來幫助你嗎?沒有任何理由不在錯誤信息中包含錯誤信息 - 再次,它在您的屏幕上顯示在您的面前*。 –

回答

0

首先,我會建議通過python的基本教程。你會發現它在未來有用。

Python堅持所謂的「越位規則」。這意味着不同的代碼塊被縮進識別。

https://en.wikipedia.org/wiki/Off-side_rule

當你複製粘貼從互聯網到您的編輯器的代碼,壓痕可能會失真。您會希望重新檢查源代碼,並使代碼與源代碼完全一致。

PS:請嘗試將錯誤消息與代碼一起發佈。

相關問題