文本文件并将其排序

时间:2015-06-12 01:52:25

标签: python sorting

这是我的代码:

names=[]
scores=[]
score_check=10

def class_name():
    print(input("What class are you in? [class1,class2,class3] "))
while True:
    class_name()
    choice=str(input("-->"))
    if class_name == "class1":
        load_data("class1")
    elif class_name == "class2":
        load_data("class2")
    elif class_name == "class3":
        load_data("class3")
    else:
        break


def main_menu():
    print("You have the following options")
    print("1)List in alphabetical order with each students highest score")
    print("2)List by the highest score, highest to lowest")
    print("3)List by the average score, highest to lowest")
    print("9)Exit")

def tidy_list(rough_list):
    new_list=[]
    for score in rough_list:
        new_list.append(int(score))
    return new_list

def load_data(group_name):
    text_file = open(group_name+".txt",'r')
    load_data(class_name)
    line=text_file.readline()
    while line:
     temp_line=line.split(',')
     names.append(line.split(',')[0])
     line=text_file.readline()
     temp_line.remove(temp_line[0])
     scores.append(tidy_list(temp_line))

def get_average(marks):
    total=0
    for score in marks:
        total= total+score
        return int(total/len(marks))

def score_vs_average():
    print("Score vs Average")
    highest_score=[]
    for student in scores:
        highest=max(student)
        highest_score.append(highest)
    print(highest_score)
    print(get_average(highest_score))
    print("Name Diff")

pos = 0
average=get_average(highest_score)
for name in names:
    print(name, abs(highest_score[pos]-average))
    pos = pos+1


while True:
    main_menu()
    choice=int(input("-->")) 
    if choice ==1:
        ()
    elif choice ==2:
        ()
    elif choice ==3:
        score_vs_average()
    else:
        break

我有三个文本文件:class1class2class3 - 所有文件都包含学生姓名和分数(例如John,5)。

我想创建一个python程序:

  1. 询问用户他们想要提交哪个班级。
  2. 创建一个主菜单,询问他们如何对该特定类进行排序。
  3. 可能的答案是:
    • 按每个学生的最高分数按字母顺序排序
    • 从最高分数到最低分数排序
    • 按平均分数排序,从最高到最低。
  4. 我试过这个,但我的大脑即将爆炸,我真的很困惑。

0 个答案:

没有答案