#coding:utf-8
def add():
while True:
with open("学生信息.txt","a") as f:
# print(f.open("E:\python\项目\学生信息管理系统"))
# f.open("E:\python\项目\学生信息管理系统","w+")
insth=input("请输入学生的学号:")
inname=input("请输入学生的姓名:")
inen=int(input("请输入学生的英语成绩:"))
inpy=int(input("请输入学生的python成绩:"))
inc=int(input("请输入学生的c++成绩:"))
student= {"id":insth,"name":inname,"english":inen,"python":inpy,"c":inc}
f.write(str(student)+'\r\n')
iy=input("是否继续添加学生:y/n")
if iy=="y":
continue
else:
break
f.close()
def delete():
while True:
delete1 = input("请输入需要删除的学号:")
f = open("学生信息.txt","rb")
strbuf = ""
for i in f.readlines():
if delete1 == eval(i)['id']:
continue
else:
strbuf += str(i)
f1 = open("学生信息.txt","w+")
f1.write(strbuf)
f1.close()
iy=input("是否继续删除学生:y/n")
if iy=="y":
continue
else:
break
def find():
while True:
find=input("要通过什么查找,名字请按1,学号请按2,退出请按q")
if find == "1":
find1=input("请输入学生姓名")
findp=1
if find == "2":
find2=input("请输入学生学号")
findp=2
f = open("学生信息.txt","rb")
st=""
for i in f.readlines():
if findp==2:
if find2 == eval(i)['id']:
print(i)
continue
elif findp==1:
if find1==eval(i)["name"]:
print(i)
else:
st+= str(i)
# print(i)
if find=="q":
break
else:
continue
def show():
# while True:
f=open("学生信息.txt","rb")
for i in f.readlines():
print(str(eval(i)))
# print(f.readlines())
# f=input("如要退出,请按q")
# if f=="q":
# break
def sum ():
f = open("学生信息.txt","rb")
student = f.readlines()
print(len(student))
def turn():
f = open("学生信息.txt","rb")
st=""
student = f.readlines()
show()
find1 = input("请输入需要查找的")
f2 = open("学生信息.txt","w+")
while True:
for i in student:
# print(type(i))
if find1==eval(i)["name"]:
insth=input("请输入学生的学号:")
inen=int(input("请输入学生的英语成绩:"))
inpy=int(input("请输入学生的python成绩:"))
inc=int(input("请输入学生的c++成绩:"))
student1= {"id":insth,"name":eval(i)["name"],"english":inen,"python":inpy,"c":inc}
f2.write(str(student1)+'\r\n')
elif find1==eval(i)["id"]:
inname=input("请输入学生的姓名:")
inen=int(input("请输入学生的英语成绩:"))
inpy=int(input("请输入学生的python成绩:"))
inc=int(input("请输入学生的c++成绩:"))
student= {"id":eval(i)["id"],"name":inname,"english":inen,"python":inpy,"c":inc}
f2.write(str(student)+'\r\n')
else:
f2.write(str(eval(i)))
a = input("是否继续修改其他学生 y/n?")
if a == 'n':
break
def sort():
f = open("学生信息.txt","rb")
student = f.readlines()
student_new = []
for i in student:
student_new.append(eval(i))
student_new.sort(key=lambda i:i['english'],reverse=True)
for j in student_new:
print(j)
# find=input("要通过什么查找,名字请按1,学号请按2,退出请按q")
# if find == "1":
# find1=input("请输入学生姓名")
# findp=1
# if find == "2":
# find2=input("请输入学生学号")
# findp=2
# if findp==2:
# if find2 == eval(i)['id']:
# print(i)
# continue
# elif findp==1:
# if find1==eval(i)["name"]:
# # f.write(st)
# print(i)
# f2 = open("学生信息.txt","w+")
# f2.write(st)
# f3.write(str(student)+'\r\n')
# else:
# st+= str(i)
# def delete():
if __name__ == '__main__':
while True:
print('''
--------------------学生信息管理系统--------------------
===================功能菜单===================
1 录入查找学生信息
2 查找学生信息
3 删除学生信息
4 修改学生信息
5 排序
6 统计学生总人数
7 显示所有学生信息
0 退出系统
==============================================
说明: 通过数字或者↑ ↓方向键选择菜单
--------------------------------------------------------
''')
choice = (input("请选择功能菜单:") )
if choice == "1":
add()
elif choice =="2":
find()
elif choice=="3":
delete()
elif choice=="4":
turn()
elif choice=="0":
break
elif choice=="7":
show()
elif choice=="6":
sum()
elif choice=="5":
sort()
# elif choice==3:
# delete()
学生管理系统源码
最新推荐文章于 2024-07-18 23:08:00 发布