#!/usr/bin/env python
# -*- coding:utf-8 -*-
students = [
{
"name":"小明",
"number":1811060320,
"_class":"电子1802"
},
{
"name":"小化",
"number":1811060321,
"_class":"电子1803"
},
{
"name":"小李",
"number":1811060322,
"_class":"电子1804"
},
{
"name":"小昕",
"number":1811060323,
"_class":"电子1805"
},
{
"name":"小贤",
"number":1811060324,
"_class":"电子1805"
}
]
flag = -1
def show():
for student in students:
print("名字是:%s\t 学号是:%-12d\t 班级是: %s\t"%(student["name"],student["number"],student["_class"]))
def add():
name = input("请输入你要添加学生的名字: ")
number = int(input("请输入你要添加学生的学号: "))
_class = input("请输入你要添加学生的班级: ")
student = {"name":name,"number":number,"_class":_class}
students.append(student)
show()
def search():
number = int(input("请输入你要查询此学生的学号:"))
for student in students:
if student["number"] == number:
print("此学生是==>名字是:%s\t 学号是:%-12d\t 班级是: %s\t"%(student["name"],student["number"],student["_class"]))
return
print("该学生被退学了^__^,找不到此人!")
def motify():
name = input("请输入你要修改的学生姓名:")
for student in students:
if student["name"] == name:
motify_student = student
print("此学生是==>名字是:%s\t 学号是:%-12d\t 班级是: %s\t"%(student["name"],student["number"],student["_class"]))
break
else:
print("找不到此学生哦")
return
Information = input("请输入该学生信息,之间用逗号分隔,若某项不修改则输入#号:")
try:
list = Information.split(",")
if list[0] == "#":
list[0] = motify_student["name"]
if list[1] == "#":
list[1] = motify_student["number"]
if list[2] == "#":
list[2] = motify_student["_class"]
motify_student["name"] = list[0]
motify_student["number"] = int(list[1])
motify_student["_class"] = list[2]
except:
print("输入的格式有误!")
#print("\n名字是:%s\t 学号是:%-12d\t 班级是: %s\t"%(motify_student["name"],motify_student["number"],motify_student["_class"]))
def delete():
number = input("请输入你要删除学生的学号:")
index = 0
for student in students:
index += 1
if student["number"] == number:
print("此学生是==>名字是:%s\t 学号是:%-12d\t 班级是: %s\t"%(student["name"],student["number"],student["_class"]))
break
flag = input("确认将该学生一键退学吗?输入Y继续..")
if flag == "Y":
students.remove(students[index-1])
return
def login():
while 1:
global flag
print("="*90)
flag = int(input("欢迎进入学生管理系统,添加学生请输1,删除请输2,查找请输3,修改请输4,查看所有学生请输5,退出请输0:"))
print("="*90)
if flag == 5:
show()
elif flag == 1:
add()
elif flag == 2:
delete()
elif flag == 3:
search()
elif flag == 4:
motify()
else :
return
login()
学生管理系统
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...