all_choose = 1
num = 1
all_student = []
def stu_insert():
stu_dict = {}
stu_name = input('请输入学生姓名:')
stu_dict['姓名'] = stu_name
stu_age = input('请输入学生年龄:')
stu_dict['年龄'] = stu_age
stu_tel = input('请输入学生电话:')
stu_dict['电话'] = stu_tel
stu_dict['学号'] = str(num).zfill(3)
all_student.append(stu_dict)
print('添加成功!')
print('1.继续')
print('2.返回')
choose = int(input('🎈请选择(1-2)'))
return choose
def see_all_student():
for stu_dict in all_student:
print(stu_dict)
def see_name_student():
stu_name = input('✨输入学生姓名:')
for stu_dict in all_student:
if stu_dict['姓名'] == stu_name:
print(stu_dict)
break
else:
print('没有查到该学生信息!')
def see_number_student():
stu_num = input('输入学生学号:')
for stu_dict in all_student:
if stu_dict['学号'] == stu_num.zfill(3):
print(stu_dict)
break
else:
print('没有查到该学生信息!')
def modify_student():
stu_num = input('输入要修改学生的学号:')
for stu_dict in all_student:
if stu_dict['学号'] == stu_num.zfill(3):
new_name = input('修改后的姓名为:')
new_age = input('修改后的年龄为:')
new_tel = input('修改后的电话为:')
stu_dict['姓名'] = new_name
stu_dict['年龄'] = new_age
stu_dict['电话'] = new_tel
print('修改成功!')
break
def delete_student():
stu_num = input('输入要删除学生的学号')
for index in range(len(all_student)):
if all_student[index]['学号'] == stu_num.zfill(3):
all_student.pop(index)
print('删除成功!')
while all_choose != 6:
print('==================================')
print('欢迎喵:')
print('1.添加学生')
print('2.查看学生')
print('3.修改学生信息')
print('4.删除学生')
print('5.返回')
print('6.退出')
print('==================================')
all_choose = int(input('请选择(1-6)'))
if all_choose == 1:
choose1 = 1
while choose1 == 1:
choose1 = stu_insert()
num += 1
if all_choose == 2:
print('1.查看所有学生')
print('2.按姓名查找')
print('3.按学号查找')
print('4.返回')
choose2 = int(input('请选择(1-4)'))
if choose2 == 1:
see_all_student()
if choose2 == 2:
see_name_student()
if choose2 == 3:
see_number_student()
if all_choose == 3:
modify_student()
if all_choose == 4:
delete_student()
day11作业
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...