import os
STU_INFO = list()
def menu():
print(" "*32,"欢迎使用学生管理系统v1.0")
print(" "*30,"1:添加学生")
print(" "*30,"2:删除学生")
print(" "*30,"3:修改学生")
print(" "*30,"4:查询学生")
print(" "*30,"5:显示所有学生")
print(" "*30,"6:退出系统")
def add_stu():
stu_name = input("请输入学生姓名:")
stu_age = input("请输入学生年龄:")
stu_phone = input("请输入学生手机号:")
# global STU_INFO
stu_dict = {}
stu_dict["name"] = stu_name
stu_dict["stu_age"] = stu_age
stu_dict["stu_phone"] = stu_phone
STU_INFO.append(stu_dict)
# STU_INFO.append(stu_name)
# STU_INFO.append(stu_age)
# STU_INFO.append(stu_phone)
# print(stu_dict)
print(STU_INFO)
def show_all_stu():
print("ID\t姓名\t年龄\t手机号\t")
i = 0
for stu_dict_tmp in STU_INFO:
# for key,value in stu_dict_tmp.items():
# print(f"学生姓名:%s" % key,value)
# print("学生姓名:",value)
# print(stu_dict_tmp)
print("%d\t%s\t%s\t%s\t" % (i,stu_dict_tmp.get("name"),stu_dict_tmp.get("stu_age"),stu_dict_tmp.get("stu_phone")))
i += 1
def del_stu():
stu_id_input = int(input("请输入学生ID:"))
if 0 <= stu_id_input < len(STU_INFO):
confirm_del = input("是否真的删除Y/N:")
if confirm_del.isalpha() and confirm_del.upper() == "Y":
del STU_INFO[stu_id_input]
def query_stu():
i = 0
query_stu_name = input("请输入学生姓名:")
for stu_dict_tmp in STU_INFO:
# if query_stu_id in stu_dict_tmp:
if stu_dict_tmp.get("name") == query_stu_name:
print("ID\t姓名\t年龄\t手机号")
print("%d\t%s\t%s\t%s\t" %(i,stu_dict_tmp.get("name"),stu_dict_tmp.get("stu_age"),stu_dict_tmp.get("stu_phone")))
# i += 1
def modify_stu():
query_stu_name = input("请输入学生姓名:")
for query_stu_dict_tmp in STU_INFO:
if query_stu_dict_tmp.get("name") == query_stu_name:
after_modification_value = input("请输入新的值:")
query_stu_dict_tmp["name"] = after_modification_value
def main():
while True:
menu()
op = input("请输入操作项:")
if op == "1":
add_stu()
elif op == "2":
del_stu()
elif op == "3":
modify_stu()
elif op == "4":
query_stu()
elif op == "5":
show_all_stu()
elif op == "6":
confirm_exit = input("是否真的退出(Y/N): ")
if confirm_exit.upper() == "Y":
break
# exit()
else:
print("输入有误")
input("请回车继续.....")
os.system("cls")
main()
标签:INFO,STU,管理系统,学生,stu,dict,print
From: https://blog.51cto.com/u_12391275/7082159