Python的成绩管理系统
就上次发的成绩管理系统感觉不是很切合实际,我就再改了一下!
def Welcome():
print("欢迎使用成绩管理系统!")
print("在这里你可以查看同学的成绩!")
def mune1():
print("1.显示数据")
print("2.查询成绩")
print("3.退出")
def mune2():
print("1.语文")
print("2.数学")
print("3.英语")
print("4.总分")
print("5.平均分")
print("6.总分排名")
print("7.退出")
def mune3():
print("1.成绩")
print("2.排名")
print("3.成绩和排名")
print("4.退出")
def GetData():
sum = []
f = open('D:/score.txt')
list = f.readlines()
for i in list[1:]:
if not i.isspace(): #排除空行
i = i.strip('\n')
i = i.split() #去除元素间的空格(任意多少个空格)
sum.append(i)
print(sum)
return sum
def Sumgrades(sum):
for i in sum:
i.append(int(i[2])+int(i[3])+int(i[4]))
return sum
def sort(sum):
grades=[]
for i in sum:
grades.append(int(i[5]))
grades.sort(reverse=True) #倒序
for j in range(len(sum)):
x=grades.index(int(sum[j][5]))
sum[j].append(x+1)
return sum
def ChineseSort(sum):
grades = []
for i in sum:
grades.append(int(i[2]))
grades.sort(reverse=True)
for j in range(len(sum)):
x = grades.index(int(sum[j][2]))
sum[j].append(x+1)
def MathSort(sum):
grades = []
for i in sum:
grades.append(int(i[3]))
grades.sort(reverse=True)
for j in range(len(sum)):
x = grades.index(int(sum[j][3]))
sum[j].append(x+1)
def EnglishSort(sum):
grades = []
for i in sum:
grades.append(int(i[4]))
grades.sort(reverse=True)
for j in range(len(sum)):
x = grades.index(int(sum[j][4]))
sum[j].append(x+1)
Welcome()
sum1=GetData()
sum=Sumgrades(sum1)
sum=sort(sum)
ChineseSort(sum)
MathSort(sum)
EnglishSort(sum)
while 1:
mune1()
x=eval(input("请输入:"))
if x==1:
print("{} {} {} {} {} {} ".format('姓名', '学号', '语文', '数学', '英语', '总分'))
for i in sum:
print("{} {} {} {} {} {} ".format(i[0],i[1],i[2],i[3],i[4],i[5]))
elif x==2:
while 1:
mune2()
x=eval(input("请输入:"))
if x==1:
x1=input("输入学号或者姓名:")
while 1:
mune3()
x=eval(input("请输入选项:"))
for i in sum:
if i[0]==x1 or i[1]==x1:
if x==1:
print("{}".format(i[2]))
print("加油,相信自己!")
elif x==2:
print("{}".format(i[7]))
elif x==3:
print("成绩为:{} 排名:第{}名".format(i[3], i[8]))
elif x != 4:
print("输入错误,请重新输入!")
elif x == 4:
continue
break
elif x == 2:
x1 = input("输入学号或者姓名:")
while 1:
mune3()
x=eval(input("请输入选项"))
for i in sum:
if i[0] == x1 or i[1] == x1:
if x==1:
print("{}".format(i[3]))
print("加油,相信自己!")
elif x==2:
print("{}".format(i[8]))
elif x==3:
print("成绩为:{} 排名:第{}名".format(i[3],i[8]))
elif x != 4:
print("输入错误,请重新输入!")
elif x == 4:
continue
break
elif x == 3:
x1 = input("输入学号或者姓名:")
while 1:
mune3()
x=eval(input("请输入选项:"))
for i in sum:
if i[0] == x1 or i[1] == x1:
if x==1:
print("{}".format(i[4]))
print("加油,相信自己!")
elif x==2:
print("{}".format(i[9]))
elif x==3:
print("成绩为:{} 排名:第{}名".format(i[3],i[8]))
elif x!=4:
print("输入错误,请重新输入!")
elif x==4:
continue
break
elif x == 4:
x1 = input("输入学号或者姓名:")
for i in sum:
if i[0] == x1 or i[1] == x1:
print("{}".format(i[5]))
print("加油,相信自己!")
elif x==5:
score=0
x1 = input("输入学号或者姓名!")
for i in sum:
if i[0] == x1 or i[1] == x1:
score=(int(i[2])+int(i[3])+int(i[4]))/3
print("{:.2f}".format(score))
print("加油,相信自己!")
elif x == 6:
x1 = input("输入学号或者姓名!")
for i in sum:
if i[0] == x1 or i[1] == x1:
print("{}".format(i[6]))
print("加油,相信自己!")
elif x==7:
break
else:
print("您输入的数字识别不了,请重新输入啊!")
elif x==3:
break
else:
print("您输入的数字识别不了,请重新输入啊!")
我的score.txt为:
姓名 学号 语文 数学 英语
龚雷 2019101 104 137 117
朱芊 2019102 100 110 110
陈香 2019103 105 100 100
魏筱 2019104 130 100 137
熊国成 2019105 120 90 100
童宝尧 2019106 130 90 110
卢功有 2019107 130 120 122
丁永亮 2019108 140 100 30
任开林 2019109 130 130 79
你可以任意添加数据!