• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
坤哥哥1
博客园    首页    新随笔    联系   管理    订阅  订阅

学生管理系统代码

"""
Python专业项目,学生管理系统
"""
"""
所用知识点:

  1. 列表的增删改查
  2. 字典的增加元素
  3. 函数的定义以及调用
    """
    """
    学生管理系统,列表,字典
  4. 新生入学,添加学生信息
  5. 信息有更动,修改学生信息
  6. 学生毕业,删除学生信息
  7. 查看学生信息,查找学生信息
    """
    import time

def print_info(): # 显示欢迎界面
print("🐱" * 30)
print("欢迎使用学生管理系统V3.3")
print("1. 添加学生信息")
print("2. 修改学生信息")
print("3. 删除学生信息")
print("4. 查询学生信息")
print("5. 退出系统")
print("🐕" * 30)

def add_student(): # 添加学生信息
global student_info # 声明函数中要修改的是全局变量student_info
dict_1 = {}
name = input("请输入学生的姓名:")
age = input("请输入学生的年龄:")
sex = input("请输入学生的性别:")
id = input("请输入学生的身份证号码:")
phone = input("请输入学生的手机号:")
dict_1["name"] = name # 通过key添加value
dict_1["age"] = age
dict_1["sex"] = sex
dict_1["id"] = id
dict_1["phone"] = phone
student_info.append(dict_1) # 将字典追加至列表中做为一个元素

def change_info(): # 修改学生信息
change = int(input("请输入要修改的学生序号:"))
global student_info
name = input("请输入新的姓名:(回车不修改)")
if len(name) != 0:
student_info[change-1]["name"] = name
age = input("请输入新的年龄:(回车不修改)")
if len(age) != 0:
student_info[change-1]["age"] = age
sex = input("请输入新的性别:(回车不修改)")
if len(sex) != 0:
student_info[change - 1]["sex"] = sex
id = input("请输入新的身份证号码:(回车不修改)")
if len(id) != 0:
student_info[change - 1]["id"] = id
if len(phone) != 0:
student_info[change - 1]["phone"] = phone

def del_info(): # 删除学生信息
del_num = int(input("请输入要删除的学生序号:"))
global student_info
del student_info[del_num-1]

def show_info(): # 显示学生信息
show_num = int(input("请输入要查询的学生序号(0代表查询所有学生信息)😊)
if show_num != 0:
for i,j in student_info[show_num-1].items():
print(show_num,i,j) # 输出字典中的key-value
elif show_num == 0:
m = 1
for temp in student_info: # 遍历列表
print("第%d序列的学生信息如下:" % m)
for x,y in temp.items(): # 遍历字典
print(x,y)
m += 1
time.sleep(2)

student_info = [{'name': '张三', 'age': '20', 'sex': '女', 'id': '123456789','phone':'138355xxxx'}] # 存放所有学生信息的列表,全局变量
while True:
print_info()
choice = input("请输入您要选择的操作(1-5)😊
if choice in ["1","2","3","4","5"]:
print("您选择的操作是",choice)
if choice == "5":
print("感谢使用本软件,再见!")
break
elif choice == "1":
print("添加学生信息")
add_student() # 添加信息的函数
print(student_info)
elif choice == "2":
print("修改学生信息")
change_info() # 修改信息的函数
print(student_info)
elif choice == "3":
print("删除学生信息")
del_info()
print(student_info)
elif choice == "4":
print("查看学生信息")
show_info()
else:
print("输入有误,请重新输入!")

posted @ 2020-10-29 14:07  坤哥哥s  阅读(236)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3