用python写的学生管理系统作业
用python做一个简单的学生管理系统,主要操作**增删改查**,没有数据持久化,用函数封装了一下,有一个**坑**就是添加数据用append新加数据会覆盖之前数据,要用上copy()方法。具体原因转移他处查看。
效果演示
简易学生管理系统演示(python3)
简易学生管理系统演示(python3)# -*- coding: utf-8 -*-
import time
stu_info_list = []
stu_info = {
}
def insert():
stu_name = input("请输入个人姓名:")
stu_info[name] = stu_name
stu_age = int(input("请输入个人年龄(18-25):"))
while stu_age not in range(18, 26):
stu_age = int(input("请输入个人年龄(18-25):"))
stu_info[age] = stu_age
stu_mobile = input("请输入个人电话号码:")
while stu_mobile.__len__() != 11:
stu_mobile = input("输入的电话号码位数不是11位!,请重新输入:")
stu_info[mobile] = stu_mobile
stu_info[register_time] = time.strftime("%Y:%m:%d %H:%M:%S", time.localtime())
#有坑的点
stu_info_list.append(stu_info.copy())
print(stu_info_list)
return stu_info_list
def delete():
delete_name = input("请输入您要删除个人的姓名:")
for item in stu_info_list:
for value in item.values():
if delete_name == value:
stu_info_list.remove(item)
print("个人信息删除成功")
print(stu_info_list)
return stu_info_list
def update():
update_name = input("请输入您要修改个人的姓名:")
for item in stu_info_list:
for value in item.values():
if update_name == value:
item[name] = input("请输入更新后的姓名:")
update_age = int(input(请输入更新后的年龄(18-25):))
while update_age not in range(18, 26):
update_age = int(input("请输入更新后的年龄(18-25):"))
item[age] = update_age
update_mobile = input("请输入更新后的手机号码:")
while update_mobile.__len__() != 11:
update_mobile = input("输入更新后的电话号码位数不是11位!,请重新输入:")
item[mobile] = update_mobile
print(stu_info_list)
return stu_info_list
def select():
select_name = input("请输入您要查找个人信息的姓名:")
for item in stu_info_list:
for value in item.values():
if select_name == value:
print(
"学生姓名:{0},学生年龄:{1},学生电话:{2},注册时间:{3}".format(item.get(name), item.get(age), item.get(mobile), item.get(register_time)))
return stu_info_list
def select_all():
for item in stu_info_list:
print("学生姓名:{0},学生年龄:{1},学生电话:{2},注册时间:{3}".format(item.get(name), item.get(age), item.get(mobile), item.get(register_time)))
return stu_info_list
def main():
while True:
print("=" * 40)
print("学生信息管理-函数版")
print("1、增加insert-个人信息")
print("2、删除delete-个人信息")
print("3、修改update-个人信息")
print("4、查询select-个人信息")
print("5、显示所有学生信息")
print("6、退出系统")
print("=" * 40 +
)
order = int(input("请输入您要操作的功能序号:"))
if order == 1:
insert()
elif order == 2:
delete()
elif order == 3:
update()
elif order == 4:
select()
elif order == 5:
select_all()
elif order == 6:
print("欢迎使用本系统")
break
if __name__ == __main__:
main()
上一篇:
通过多线程提高代码的执行效率例子
