【发布时间】:2017-05-23 15:24:17
【问题描述】:
def individual_question_scores_pretest():
question_number = 1
for name in students:
print("Now we will input the scores for %s: " % name)
while question_number <= number_of_questions:
questionScore = float(raw_input("Score for question # %d: " %
question_number))
question_scores_preTest[name] = questionScore
question_number = question_number + 1
return question_scores_pretest
我试图让这个 while 循环通过 number_of_questions 定义的一组有限的问题编号。目前 number_of_questions 设置为 10。所以我想输入问题 #1、问题 #2 等的分数一直到 10。但是,它一直到 11、12、13、14... 作为无限环形。我的缩进是错误的还是我的流程顺序? 谢谢!
【问题讨论】:
-
number_of_questions在哪里定义?它是什么类型的? -
btw
question_scores_preTest命名不一致 -
number_of_questions 在此之前定义为全局变量:
-
number_of_questions = raw_input("请输入测评题数:")
-
@George 您似乎正在将数字与字符串进行比较。我不记得这会在 Python 中导致什么,但可能没什么好处。不过我预计会出错。
标签: python while-loop counter python-2.x