Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python数学测验从txt文件导入数据并对其进行组织_Python_Sorting - Fatal编程技术网

Python数学测验从txt文件导入数据并对其进行组织

Python数学测验从txt文件导入数据并对其进行组织,python,sorting,Python,Sorting,我目前正在做OCR计算机科学A453 CA,总结一下,我被分配了3项任务,我已经完成了前2项任务,但最后一项任务确实给我带来了问题。我的出发点是将数学考试的分数保存到txt文件中。文件孩子的姓名和分数保存在与其类相关的文件中。对于任务3,我现在被要求导入这些数据,以查找从高到低排列的平均分数和最高分数,以及按字母顺序排列的分数。我试了又试,但找不到解决这项任务的办法。我已经删除了我所有的实验代码,试图让它工作,并留下了代码,直到分数保存。这将是一个伟大的帮助,以找到一个解决方案,甚至一些好的指针

我目前正在做OCR计算机科学A453 CA,总结一下,我被分配了3项任务,我已经完成了前2项任务,但最后一项任务确实给我带来了问题。我的出发点是将数学考试的分数保存到txt文件中。文件孩子的姓名和分数保存在与其类相关的文件中。对于任务3,我现在被要求导入这些数据,以查找从高到低排列的平均分数和最高分数,以及按字母顺序排列的分数。我试了又试,但找不到解决这项任务的办法。我已经删除了我所有的实验代码,试图让它工作,并留下了代码,直到分数保存。这将是一个伟大的帮助,以找到一个解决方案,甚至一些好的指针上做什么!谢谢:)

代码:


很抱歉,格式很糟糕,但我无法让代码正确粘贴,如果您有任何建议可以正确发布,请说要正确设置代码格式,您可以在编辑器中突出显示它,然后按control+K或单击看起来像{}的按钮。啊,非常感谢,我没有主意了,需要一些建议,我不是要完整的答案,只是要一些提示:)
username=input("What is your name?") #childs name variable
group=int(input("What class number are you, 1, 2 or 3?")) #this determines which file the score will be saved in
print ("Welcome {} to the Arithmetic quiz".format(username))#The introduction to the quiz

correctAnswers=0
for question_number in range(10):
    if test():
        correctAnswers +=1

print("{}: You got {} answers correct".format(username, correctAnswers))


if group==1:#If the childs class 1,their score will be saved in the file for the class:1
    with open("class1.txt","a+") as f:
        f.write("{}:{}".format(username,correctAnswers))
if group==2:#If the childs class is equal to 2, the file will be saved in the file for class:2
    with open("class2.txt","a+") as f:
        f.write("{}:{}".format(username,correctAnswers))
if group==3:#If the childs class is equal to 3, the file will be saved in the file for class:3
    with open("class3.txt","a+") as f:
        f.write("{}:{}".format(username,correctAnswers))