user1 = {'username':'张三', 'password':'123456'}
user_id = "1"
user_dict = {
'1':user1
}
stu_dict = {}
def homepage1():
while True:
print("\t\t学生管理系统")
print("- * - * - * - * - * - * - * - * - * - * - * -")
print("\t\t1. 管理员登录")
print("\t\t2. 管理员注册")
print("\t\t3. 退出系统")
print("- * - * - * - * - * - * - * - * - * - * - * -")
c = input("请输入您的选项:")
if c == "1":
longin()
elif c == "2":
register() #注册
elif c == "3":
exit()
else:
input("输入有误,按任意键返回首页。")
def register():
"""操作员注册"""
username = input("请输入注册账号:").strip()
password = input("请输入账号密码:").strip()
global user_id
user_id = int(user_id) + 1
user_id = str(user_id)
new_user = {
'username': username,
'password': password
}
# for key,value in user_dict.items():
# if value == new_user1:
# input("当前账号已存在,按任意键返回。")
# break
if new_user in user_dict.values():
c = input("当前账号已存在,请输入(1-返回首页,其他-重新输入账号和密码注册)。")
if c == "1":
return homepage1()
else:
return register()
else:
user_dict[user_id] = new_user
print(user_dict)
# print("姓名\t\t密码")
# for key, value in user_dict.items():
# print(user_dict[key]['username'], user_dict[key]['password'],sep="\t\t")
return homepage1()
def longin():
username = input("请输入账号:").strip()
password = input("请输入密码:").strip()
new_user = {
'username': username,
'password': password
}
# for key, value in user_dict.items():
# if value['username'] == username and value['password'] == password:
# print("登录成功")
if new_user in user_dict.values():
print("登录成功")
while True:
entry(username)
else:
input("账号或密码有误,按任意键返回。")
return homepage1()
def entry(name):
print("\t\t学生管理系统-主页---[当前用户:",name,"]")
print("~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~")
print("\t\t1. 录入学员信息")
print("\t\t2. 删除学员信息")
print("\t\t3. 修改学员信息")
print("\t\t4. 查询学员信息")
print("\t\t5. 返回首页")
print("~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~")
c = input("请输入您的选项:")
if c == "1":
id = input("请输入学号:").strip()
name = input("请输入姓名:").strip()
age = input("请输入年龄:").strip()
gender = input("请输入性别(男/女):").strip()
score = input("请输入计算机成绩:").strip()
new_dict = {
'id':id,
'name':name,
'age':age,
'gender':gender,
'score':score
}
stu_dict[id] = new_dict
#print(stu_dict)
elif c == "2":
c = input("请输入您要删除学员的学号:")
if c in stu_dict.keys():
print("\t\t学生管理系统-学员信息查看")
print("----------------------------------------")
print("学号\t姓名\t年龄\t性别\t计算机成绩")
print(stu_dict[c].get('id'),stu_dict[c].get('name'),stu_dict[c].get('age'),stu_dict[c].get('gender'),stu_dict[c].get('score'),sep="\t")
a = input("确定要删除该学生信息吗(Y/N):")
if a == "Y":
del stu_dict[c]
#print(stu_dict)
input("该学员信息已删除,按任意键返回主页")
else:
input("取消删除,按任意键返回主页")
entry(name)
else:
input("该学员不存在,按任意键返回主页")
entry(name)
elif c == "3":
#修改学生信息
c1 = input("请输入您要修改学员的学号:").strip()
if c1 in stu_dict.keys():
print("\t\t学生管理系统-学员信息查看")
print("----------------------------------------")
print("学号\t姓名\t年龄\t性别\t计算机成绩")
print(stu_dict[c1].get('id'), stu_dict[c1].get('name'), stu_dict[c1].get('age'), stu_dict[c1].get('gender'),
stu_dict[c1].get('score'), sep="\t")
c2 = input("请输入要修改的属性(1.姓名 2.性别 3.年龄):")
if c2 == "1": # 修改姓名
name = input("请输入新的姓名:")
stu_dict[c1]["name"] = name
elif c2 == "2": # 修改性别
gender = input("请输入新的性别:")
stu_dict[c1]["gender"] = gender
elif c2 == "3": # 修改年龄
age = input("请输入新的年龄:")
stu_dict[c1]["age"] = age
print(stu_dict[c1])
input("修改成功,按任意键返回主页。")
else:
input("未找到该学员,按任意键返回。")
entry(name)
elif c == "4":
#查询所有学生信息
print("\t\t学生管理系统-学员信息查看")
print("----------------------------------------")
print("学号\t姓名\t年龄\t性别\t计算机成绩")
for key,value in stu_dict.items():
print(value['id'],value['name'],value['age'],value['gender'],value['score'],sep="\t")
elif c == "5":
name = None
homepage1()
else:
input("输入有误,按任意键返回重新选择")
entry()
if __name__ == "__main__":
homepage1()
学生管理系统------python练习
最新推荐文章于 2024-11-05 15:32:33 发布