该计划的目标是比较学生答案列表和正确答案列表,并计算有多少答案是正确的。答案键存储为字符串列表,学生答案从文本文件中读取,然后转换为大写以匹配答案键。你知道吗
#Read student answer file
student_answers = infile.read()
#Convert student answer to all caps
student_answers = [answer.upper() for answer in student_answers]
我的程序运行没有错误,但是比较两个列表的结果是不正确的。只有3个答案是正确的,有20个答案是正确的。下面是到目前为止我已经完成的相关代码,我还包括了输出Program Output Image的屏幕截图。只有问题1、3、5、7和25应标记为不正确。我仔细检查了两个列表,它们包含正确的信息,所以它不是输入错误。任何关于我可能出错的指导都将不胜感激。你知道吗
for studentLine, keyLine in zip(Student, TestKey):
keyAnswer = keyLine.split()
studentAnswer = studentLine.split()
#Compare student answer to test key
if studentAnswer == keyAnswer:
correct += 1
percent_score += 4
print('Good job! Question ', index + 1, 'is correct!')
index +=1
if studentAnswer != keyAnswer:
incorrect += 1
incorrect_list.append(index + 1)
print('The correct answer to question ', index + 1, 'is ', TestKey[index])
index +=1
我认为你没有剥皮,而是剪开了。你知道吗
所以你应该使用:
相关问题 更多 >
编程相关推荐