python学生信息管理系统实现代码
作者:xiaoxaoyu 时间:2021-07-01 03:41:18
python实现学生信息管理系统,供大家参考,具体内容如下
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import re
import os
# 主函数
def main():
ctrl = True
while (ctrl):
menu()
option = input("请选择:")
option_str = re.sub("\D", "", option)
if option_str in ['0', '1', '2', '3', '4', '5', '6', '7']:
option_int = int(option_str)
if option_int == 0:
print("您已退出学生信息管理系统!")
ctrl = False
elif option_int == 1:
insert()
elif option_int == 2:
search()
elif option_int == 3:
delete()
elif option_int == 4:
modify()
elif option_int == 5:
sort()
elif option_int == 6:
total()
elif option_int == 7:
show()
# 显示主菜单
def menu():
print("""
-------------------学生信息管理系统---------------------
======================功能菜单=========================
1 录入学生信息
2 查找学生信息
3 删除学生信息
4 修改学生信息
5 排序
6 统计学生总人数
7 显示所有学生信息
0 退出系统
======================================================
说明:通过数字或上下方向键选择菜单
------------------------------------------------------
""")
# 向指定文件写入指定内容的函数
filename = "students.txt"
def save(student):
try:
students_txt = open(filename, "a")
except:
students_txt = open(filename, "w")
for info in student:
students_txt.write(str(info) + "\n")
students_txt.close()
# 1 录入学生信息
def insert():
studentList = []
mark = True
while mark:
id = input("请输入ID(如1001):")
if not id:
break
name = input("请输入名字:")
if not name:
break
try:
english = int(input("请输入英语成绩:"))
python = int(input("请输入Python成绩:"))
c = int(input("请输入C语言成绩:"))
except:
print("输入无效,不是整型数值....重新录入信息")
continue
# 信息保存到字典
student = {"id": id, "name": name, "english": english, "python": python, "C语言": c}
studentList.append(student)
inputMark = input("是否继续添加?(y/n):")
if inputMark == "y":
mark = True
else:
mark = False
save(studentList)
print("学生信息录入完毕!")
# 2 查找学生信息
def search():
mark = True
student_query = []
while mark:
id = ""
name = ""
if os.path.exists(filename):
mode = input("按ID查输入1,按姓名查输入2:")
if mode == "1":
id = input("请输入学生ID:")
elif mode == "2":
name = input("请输入学生姓名:")
else:
print("您的输入有误,请重新输入!")
search()
with open(filename, 'r') as file:
student = file.readlines()
for list in student:
d = dict(eval(list))
if id is not "":
if d['id'] == id:
student_query.append(d)
elif name is not "":
if d['name'] == name:
student_query.append(d)
show_student(student_query)
student_query.clear()
inputMark = input("是否继续查询?(y/n):")
if inputMark == "y":
mark = True
else:
mark = False
else:
print("暂未保存数据信息...")
return
def show_student(studentList):
if not studentList:
print("无数据信息")
return
format_title = "{:^6}{:^12}\t{:^8}\t{:^10}\t{:^10}\t{:^10}"
print(format_title.format("ID", "名字", "英语成绩", "Python成绩", "C语言成绩", "总成绩"))
format_data = "{:^6}{:^12}\t{:^12}\t{:^12}\t{:^12}\t{:^12}"
for info in studentList:
print(format_data.format(info.get("id"), info.get("name"), str(info.get("english")), str(info.get("python")),
str(info.get("C语言")),
str(info.get("english")+info.get("python")+info.get("C语言")).center(12)))
# 3 删除学生信息
def delete():
mark = True
while mark:
studentId = input("请输入要删除的学生ID:")
if studentId is not "":
if os.path.exists(filename):
with open(filename, 'r') as rfile:
student_old = rfile.readlines()
else:
student_old = []
ifdel = False
if student_old:
with open(filename, 'w') as wfile:
d = {}
for list in student_old:
d = dict(eval(list))
if d['id'] != studentId:
wfile.write(str(d) + "\n")
else:
ifdel = True
if ifdel:
print("ID为%s的学生信息已经被删除..." % studentId)
else:
print("没有找到ID为%s的学生信息..." % studentId)
else:
print("无学生信息...")
break
show()
inputMark = input("是否继续删除?(y/n):")
if inputMark == "y":
mark = True
else:
mark = False
# 4 修改学生信息
def modify():
show()
if os.path.exists(filename):
with open(filename, 'r') as rfile:
student_old = rfile.readlines()
else:
return
studentid = input("请输入要修改的学生ID:")
with open(filename, "w") as wfile:
for student in student_old:
d = dict(eval(student))
if d["id"] == studentid:
print("找到了这名学生,可以修改他的信息!")
while True:
try:
d["name"] = input("请输入姓名:")
d["english"] = int(input("请输入英语成绩:"))
d["python"] = int(input("请输入Python成绩:"))
d["C语言"] = int(input("请输入C语言成绩:"))
except:
print("输入信息有误,重新输入")
else:
break
student = str(d)
wfile.write(student + "\n")
print("修改成功!")
else:
wfile.write(student)
mark = input("是否继续修改其他学生信息?(y/n):")
if mark == "y":
modify()
# 5 排序
def sort():
show()
if os.path.exists(filename):
with open(filename, 'r') as file:
student_old = file.readlines()
student_new = []
for list in student_old:
d = dict(eval(list))
student_new.append(d)
else:
return
ascOrDesc = input("请选择(0升序;1降序):")
if ascOrDesc == "0":
ascOrDescBool = False
elif ascOrDesc == "1":
ascOrDescBool = True
else:
print("您的输入有误,请重新输入!")
sort()
mode = input("请选择排序方式(1按英语排序;2按Python排序;3按C语言排序;0按总成绩排序)")
if mode == "1":
student_new.sort(key=lambda x: x["english"], reverse=ascOrDescBool)
elif mode == "2":
student_new.sort(key=lambda x: x["python"], reverse=ascOrDescBool)
elif mode == "3":
student_new.sort(key=lambda x: x["C语言"], reverse=ascOrDescBool)
elif mode == "0":
student_new.sort(key=lambda x: x["english"] + x["python"] + x["C语言"], reverse=ascOrDescBool)
else:
print("您的输入有误,请重新输入!")
sort()
show_student(student_new)
# 6 统计学生总人数
def total():
if os.path.exists(filename):
with open(filename, 'r') as rfile:
student_old = rfile.readlines()
if student_old:
print("一共有%s名学生" % len(student_old))
else:
print("还没有录入学生信息!")
else:
print("暂未保存数据信息...")
# 7 显示所有学生信息
def show():
student_new = []
if os.path.exists(filename):
with open(filename, 'r') as rfile:
student_old = rfile.readlines()
for list in student_old:
student_new.append(eval(list))
if student_new:
show_student(student_new)
else:
print("暂未保存数据信息...")
# 0 退出系统
if __name__ == '__main__':
main()
安装pyinstaller打包成可执行exe文件
pip install pyinstaller
...
(pydemo) D:\JavaProjects\PythonProject\01学生信息管理系统>pyinstaller --version
4.3
(pydemo) D:\JavaProjects\PythonProject\01学生信息管理系统>pyinstaller -F D:\JavaProjects\PythonProject\01学生信息管理系统\StuManagerSys.py
在下面的路径即可找到打包后的exe文件
来源:https://blog.csdn.net/xiaoxaoyu/article/details/117970316
标签:python,管理系统
0
投稿
猜你喜欢
浅析Python中的getattr(),setattr(),delattr(),hasattr()
2022-11-10 08:26:41
ASP 自动采集实现代码
2011-03-07 11:17:00
Golang中的int类型和uint类型到底有多大?
2024-04-25 15:04:44
PHP中substr_count()函数获取子字符串出现次数的方法
2023-11-14 14:28:17
python的迭代器与生成器实例详解
2021-06-21 15:36:41
免费手机号码归属地API查询接口和PHP使用实例分享
2023-10-31 08:06:37
ServerXMLHTTP的setTimeouts超时设置
2010-01-02 20:38:00
浅谈python中scipy.misc.logsumexp函数的运用场景
2023-11-10 17:10:56
python常见字符串处理函数与用法汇总
2023-10-19 08:07:11
vue实现一个懒加载的树状表格实例
2023-07-02 17:06:45
asp如何使用MsChart制图工具?
2010-06-05 12:40:00
Python基于mysql实现学生管理系统
2024-01-24 05:57:47
ACCESS数据库的压缩,备份,还原,下载,删除的实现
2024-01-18 16:16:26
asp数组使用特法
2009-05-11 12:43:00
Springboot项目对数据库用户名密码实现加密过程解析
2024-01-19 23:02:04
Python使用APScheduler实现定时任务过程解析
2023-01-23 19:20:35
PHP 接入微信扫码支付总结(总结篇)
2024-05-13 09:53:31
Python SQLite3简介
2023-05-29 11:26:01
Python 条件判断的缩写方法
2021-04-20 16:06:20
阿里云OSS实践文件直传基于服务端
2024-05-13 09:35:27