|
发表于 2021-12-9 03:23:51
|
显示全部楼层
- dictname = {}
- one_result = []
- two_result = []
- three_result =[]
- sum_result=[]
- count = []
- while True:
- print("1.从键盘上录入学生个数")
- print("2.依次录入学生学号、语文、数学、英语成绩")
- print("3.输入完成后,显示学号成绩及总分")
- print("4.设计排序系统")
- print("输入负数:退出查询")
- cmd = eval(input("请输入命令"))
- if cmd == 1:
- number = eval(input("请输入需要录入的学生个数:"))
- for i in range(number):
- data = input("请输入学号,语文,数学,英语成绩,(每项用逗号分开)").split(",")
- count.append(data[0])
- one = int(data[1])
- two = int(data[2])
- three = int(data[3])
- one_result.append(one)
- two_result.append(two)
- three_result.append(three)
- sum = one+two+three
- sum_result.append(sum)
- dictname[data[0]] = [one,two,three,sum]
- print("{} {} {} {} {}".format("学号","语文","数学","英语","总分"))
- for j in count:
- print("{} {} {} {} {}".format(j,dictname[j][0],dictname[j][1],dictname[j][2],dictname[j][3]))
- print(dictname)
- elif cmd == 4:
- print("输入1:按语文降序\n"
- "输入2:按数学降序\n"
- "输入3:按英语降序\n"
- "输入4:按总分降序\n"
- "输入5:按语文升序\n"
- "输入6:按数学升序\n"
- "输入7:按英语升序\n"
- "输入8:按总分升序")
- number = eval(input("请输入命令"))
- if number > 8 :
- print("命令输入错误")
- continue
- elif number<0:
- break
- else:
- if number == 1:
- new_result = one_result
- new_result.sort(reverse=True)
- print("{} {} {} {} {}".format("学号","语文","数学","英语","总分"))
- for i in new_result:
- for j in count:
- if i==dictname[j][0]:
- print("{} {} {} {} {}".format(j,dictname[j][0],dictname[j][1],dictname[j][2],dictname[j][3]))
- elif number == 2:
- new_result = two_result
- new_result.sort(reverse=True)
- print("{} {} {} {} {}".format("学号","语文","数学","英语","总分"))
- for i in new_result:
- for j in count:
- if i==dictname[j][1]:
- print("{} {} {} {} {}".format(j,dictname[j][0],dictname[j][1],dictname[j][2],dictname[j][3]))
- elif number == 3:
- new_result = three_result
- new_result.sort(reverse=True)
- print("{} {} {} {} {}".format("学号", "语文", "数学", "英语", "总分"))
- for i in new_result:
- for j in count:
- if i==dictname[j][2]:
- print("{} {} {} {} {}".format(j,dictname[j][0],dictname[j][1],dictname[j][2],dictname[j][3]))
- elif number == 4:
- new_result = sum_result
- new_result.sort(reverse=True)
- print("{} {} {} {} {}".format("学号", "语文", "数学", "英语", "总分"))
- for i in new_result:
- for j in count:
- if i==dictname[j][3]:
- print("{} {} {} {} {}".format(j,dictname[j][0],dictname[j][1],dictname[j][2],dictname[j][3]))
- elif number == 5:
- new_result = one_result
- new_result.sort()
- print("{} {} {} {} {}".format("学号","语文","数学","英语","总分"))
- for i in one_result:
- for j in count:
- if i==dictname[j][0]:
- print("{} {} {} {} {}".format(j,dictname[j][0],dictname[j][1],dictname[j][2],dictname[j][3]))
- elif number == 6:
- new_result = two_result
- new_result.sort()
- print("{} {} {} {} {}".format("学号","语文","数学","英语","总分"))
- for i in two_result:
- for j in count:
- if i==dictname[j][1]:
- print("{} {} {} {} {}".format(j,dictname[j][0],dictname[j][1],dictname[j][2],dictname[j][3]))
- elif number == 7:
- new_result = three_result
- new_result.sort()
- print("{} {} {} {} {}".format("学号","语文","数学","英语","总分"))
- for i in three_result:
- for j in count:
- if i==dictname[j][2]:
- print("{} {} {} {} {}".format(j,dictname[j][0],dictname[j][1],dictname[j][2],dictname[j][3]))
- elif number == 8:
- new_result = sum_result
- new_result.sort()
- print("{} {} {} {} {}".format("学号", "语文", "数学", "英语", "总分"))
- for i in sum_result:
- for j in count:
- if i==dictname[j][3]:
- print("{} {} {} {} {}".format(j,dictname[j][0],dictname[j][1],dictname[j][2],dictname[j][3]))
- if cmd<0:
- break
复制代码 |
|