與scores_on_pretest
功能發生故障。功能中的流量控制
如果我輸入兩個名字,說喬和鮑勃,當腳本達到此功能,它要求的分數問題#1喬,然後問題#1鮑勃,則問題2喬等
我想要做的就是首先爲Joe提出所有問題,然後轉向Bob。我知道它一定是在錯誤的地方表達,但似乎無法找到哪一個。
感謝您的任何建議!
students_pretest = []
print "First we will collect the student names on the pre-test."
def student_names_pretest():
while True:
name = raw_input("Type in a name or type 'done':")
if name == "done":
break
students_pretest.append(name)
students_pretest.sort()
print students_pretest
student_names_pretest()
pretest_scores = {}
for name in students_pretest:
pretest_scores['%s' % name] = []
question_number = int(raw_input("How many questions are on this assessment?: "))
def scores_on_pretest():
current_question = 1
while current_question <= question_number:
for student in pretest_scores:
print "Pre-test scores for %s" % student
score = int(raw_input("Enter a score for Question #%d: " % current_question))
pretest_scores[student].append(score)
current_question =+ current_question + 1
print pretest_scores
scores_on_pretest()
請將「python」標籤添加到您的問題中。 – Bacon
你是否嘗試顛倒你的循環順序?所以你迭代外循環中的學生然後迭代內循環中的問題?另外請注意,當您將學生存儲在字典中時,它不會保留您輸入學生姓名的順序。 –