一个简单的学生管理系统
import copy
student1 = {'姓名': 0, '年龄': 0, '电话': 0, '学号': 0}
ID1 = 1808000
class1 = []
index = len(class1)
while True:
print('1.添加学生')
print('2.查看学生')
print('3.修改学生信息')
print('4.删除学生')
print('5.返回')
num1 = int(input('请选择(1-5)'))
if num1 == 5:
print('1.添加学生')
print('2.查看学生')
print('3.修改学生信息')
print('4.删除学生')
print('5.返回')
continue
if num1 == 1:
while True:
name = input('请输入学生姓名')
age = int(input('请输入学生年龄'))
tel = int(input('请输入学生电话'))
ID1 += 1
str1 = str(ID1)
student1['姓名'] = name
student1['年龄'] = age
student1['电话'] = tel
student1['学号'] = ID1
student2 = copy.deepcopy(student1)
class1.insert(index, student2)
print('添加成功')
choice_1 = int(input('1.继续\n2.返回'))
if choice_1 == 2:
break
elif num1 == 2:
while True:
print('1.查看所有学生')
print('2.按姓名查找')
print('3.按学号查找')
print('4.返回')
choice_2 = int(input('请选择(1-4)'))
if choice_2 == 1:
for items in class1:
print(items)
elif choice_2 == 2:
name2 = input('请输入姓名')
for student1 in class1:
if student1.get('姓名') == name2:
print(student1)
continue
elif choice_2 == 3:
ID2 = int(input('请输入学号'))
for student1 in class1:
if student1.get('学号') == ID2:
print(student1)
continue
else:
break
elif num1 == 3:
for student1 in class1:
print(student1)
name3 = input('请输入需要修改学生姓名')
if student1.get('姓名') == name3:
key1 = input('请输入需要修改的项目')
value1 = input('修改为')
student1[key1] = value1
print(student1)
break
elif num1 ==4:
name4 = input('请输入需要删除的学生姓名')
for student1 in class1:
if student1.get('姓名') == name4:
class1.remove(student1)
break
else:
print('错误操作')
continue