运行展示:
代码实现:
user_dict = {
"001": {"id": "001", "password": "123456"},
"002": {"id": "002", "password": "321321"}
}
stu_dict = {
"001": {"id": "001", "name": "tom", "age": "18", "sex": "男", "score": "98"},
"002": {"id": "002", "name": "jerry", "age": "19", "sex": "女", "score": "97"},
"003": {"id": "003", "name": "joker", "age": "30", "sex": "女", "score": "60"}
}
while True:
print(" 学生管理系统")
print("- * - * - * - * - * - * - * - * - * - * - * - * - * -")
print(" 1. 操作员登录")
print(" 2. 操作员注册")
print(" 3. 退出系统")
print("- * - * - * - * - * - * - * - * - * - * - * - * - * -")
a = int(input("请输入选项"))
if a == 1:
user_id = input("请操作员输入账号")
user_passwd = input("请输入密码")
for user in user_dict.values():
if user_id == user.get("id") and user_passwd == user.get("password"):
# 展示登录成功界面
print("登录成功!")
while True:
print("学生管理系统-主页")
print("- * - * - * - * - * - * - * - * - * - * - * - * - * -")
print("1. 录入学员信息")
print("2. 删除学员信息")
print("3. 查询学员信息")
print("4. 退出系统")
print("- * - * - * - * - * - * - * - * - * - * - * - * - * -")
b = int(input("请输入选项:"))
if b == 1:
id = input("请输入学生账号:")
name = input("请输入学生姓名:")
age = input("请输入学生年龄:")
sex = input("请输入学生性别:")
score = input("请输入学生成绩:")
stu_dict1 = {
"id": id, "name": name, "age": age, "sex": sex, "score": score
# name, age, gender, score
}
stu_dict[id] = stu_dict1
input("录入完成按任意键退出!")
continue
elif b == 2:
stu_id = input("请输入你要删除的学员id:")
for stu in stu_dict.values():
if stu_id == stu.get('id'):
# 展示要删除的学员信息
print("----------------------------------------")
print("学号--|--姓名--|--年龄--|--性别--|--计算机成绩--|")
print(stu.get("id"), stu.get("name"), stu.get("age"),
stu.get("sex"), stu.get("score"), sep="--|--")
print("----------------------------------------")
isDel = input("确定要删除该学员吗(Y/N)?")
if isDel.upper() == "Y":
del stu_dict[stu_id]
input("学员信息删除成功,按任意键返回主页")
else:
input("用户取消了删除操作,按任意键返回主页")
break
else:
input("未找到该学员,请检查编号是否正确,按任意键返回上一级")
elif b == 3:
print("学号--+--姓名--+--年龄--+--性别--+--计算机成绩")
for stu in stu_dict.values():
print(stu.get("id"), stu.get("name"), stu.get("age"),stu.get("sex"), stu.get("score"),)
input("查询完成按任意键退出!")
continue
else:
input("密码错误,按任意键返回")
elif a == 2:
print(" 管理员注册")
print("- * - * - * - * - * - * - * - * - * - * - * - * - * -")
user_id = input("请输入您的账号")
user_passwd = input("请输入您的密码")
user_dict[user_id] = {"id": user_id, "password": user_passwd}
input("注册成功,按任意键返回主页面")