ADD file via upload

main
peasqyv93 2 years ago
parent b3250f0ecc
commit 09edb5a09a

@ -0,0 +1,116 @@
import os.path
import string
class_text = []
def menu(): # 菜单
print("请选择如下功能:")
print("1.添加学员;")
print("2.删除学员;")
print("3.修改学员信息;")
print("4.查询学员信息;")
print("5.显示所有成员信息;")
print("6.保存学员信息;")
print("7.退出系统;")
filename = 'student.txt'
def main():
while True:
menu()
choice = int(input('请选择您需要的功能序号:\n'))
if choice in [1, 2, 3, 4, 5, 6, 7]:
if choice == 7:
answer = input('您确定要退出系统y/n\n')
if answer == 'y' or answer == 'Y':
print('感谢您的使用,祝您生活愉快,再见!!')
break
else:
continue
elif choice == 1: # 添加学员
insert()
elif choice == 2: # 删除学员
delete()
elif choice == 3: # 修改学员信息
modify()
elif choice == 4: # 查询学员信息
search()
elif choice == 5: # 显示所有成员信息
show()
elif choice == 6: # 保存学员信息
save()
else:
print("没有该选项,请输入正确数字!!")
def insert(): # 1 添加
global class_text
while True:
name = input("请输入学员姓名:")
if not name:
break
sex = input("请输入学员性别:")
nub = int(input("请输入学员手机号:"))
student = {"name": name, "sex": sex, "nub": nub}
class_text.append(student)
answer = input("是否继续添加y/n\n")
if answer == 'y' or answer == 'Y':
continue
else:
break
print("学员信息已录入")
def save(): # 6 保存
print("保存成功")
def delete(): # 2 删除
global class_text
name = input('请输入要删除的学生的姓名:')
for student in class_text:
if student['name'] == name:
class_text.remove(student)
print("删除成功!")
return 0
print('无学生信息')
return None
def modify(): # 3 修改
global class_text
name = input('请输入要修改的学员的姓名:')
for student in class_text:
if student['name'] == name:
print('找到学生信息,可以修改他的相关信息了!')
student['name'] = input('请重新输入姓名:')
student['sex'] = input('请重新输入性别:')
student['nub'] = input('请重新输入手机号:')
print("修改成功!!!!")
return 0
print("不存在该学生信息,请检查学生姓名后重新输入!")
return None
def search(): # 4 查询
global class_text
name = input("请输入要查询的学生姓名:")
for student in class_text:
if student['name'] == name:
print("姓名:{}\n性别:{}\n手机号:{}".format(student["name"], student['sex'], student['nub']))
return 0
print("查询失败,请输入正确姓名!")
def show(): # 5 显示
global class_text
print("%-10s%-5s%-5s" % ("姓名", "性别", "手机号"))
for student in class_text:
print("%-10s%-5s%-5s" % (student["name"], student["sex"], student["nub"]))
if __name__ == '__main__':
main()
Loading…
Cancel
Save