我复制并粘贴了一些代码,如何自动化无聊的东西,这个消息不断涌现。我已经尝试更改空格或制表符的数量,并尝试使用sublime文本进行各种操作。请帮忙。
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)
答案 0 :(得分:0)
首先,我建议您阅读python中的基本教程。你会发现它在将来很有用。
Python坚持所谓的"越位规则"。这意味着不同的代码块由缩进识别。
https://en.wikipedia.org/wiki/Off-side_rule
当您将代码从Internet粘贴到编辑器时,缩进可能会失真。您可能需要重新检查源并使代码与源中的代码完全对齐。
PS:请尝试将错误消息与代码一起发布。