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

时间:2015-03-24 21:43:39

标签: python sorting

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

CODE:

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))         

0 个答案:

没有答案