def menu():
print('=====欢迎进入学生管理系统=====\n1.添加学生\n2.查找学生\n3.删除学生\n9.退出系统'+'\n'+'='*30)
global order
order=input('请选择你需要的操作:')
def back():
print('='*30+'\n1.继续\n2.返回目录'+'\n'+'='*30)
order1=input('请选择你需要的操作:')
return order1
def num():
with open('./manage.json') as f:
student_manage = json.load(f)
num = 2012084020001
for student in student_manage:
if student['学号']>=num:
num=student['学号']+1
while True:
yield num
num+=1
def add_student():
global student_manage
global ge1
try:
with open('./manage.json') as f:
student_manage = json.load(f)
except :
with open('./manage.json', 'w') as f:
str1=json.dumps([])
f.write(str1)
with open('./manage.json') as f:
student_manage = json.load(f)
student ={}
name = input('输入添加学生姓名:')
student['姓名'] = name
age = input('输入年龄:')
student['年龄'] = age
phone = input('输入电话:')
student['电话'] = phone
student_num=next(ge1)
student['学号'] = student_num
student = {'姓名': name, '年龄': age, '电话': phone, '学号': student_num}
student_manage.append(student)
with open('./manage.json', 'w') as f:
str1 = json.dumps(student_manage)
f.write(str1)
def find_student():
try:
with open('./manage.json') as f:
student_manage = json.load(f)
except :
with open('./manage.json', 'w') as f:
str1=json.dumps([])
f.write(str1)
with open('./manage.json') as f:
student_manage = json.load(f)
print('='*30+'\n1.查找学生\n2.查看所有'+'\n'+'='*30)
order1=input('请选择你需要的操作:')
if order1=='1':
name=input('输入学生姓名:')
k=0
for student in student_manage:
if student.get('姓名')==name:
print(student)
k+=1
if k==0:
print('**没有这个学生**')
elif order1=='2':
for student in student_manage:
print(student)
if len(student_manage)==0:
print('**没有任何学生信息**')
else:
print('**请正确操作**')
find_student()
def del_student():
try:
with open('./manage.json') as f:
student_manage = json.load(f)
except :
with open('./manage.json', 'w') as f:
str1=json.dumps([])
f.write(str1)
with open('./manage.json') as f:
student_manage = json.load(f)
name=input('请输入删除学生姓名:')
k=0
del_stu=[]
for student in student_manage[:]:
if student.get('姓名')==name:
del_stu.append(student)
if len(del_stu)==0:
print('**没有这个学生**')
elif len(del_stu)==1:
student_manage.remove(del_stu[0])
print('已删除学生:'+del_stu[0]['姓名'])
else:
x=1
for student1 in del_stu:
print(x,student1)
x+=1
y=input('删除学生序号:')
y=int(y)
student_manage.remove(del_stu[y-1])
with open('./manage.json', 'w') as f:
str1 = json.dumps(student_manage)
f.write(str1)
import json
ge1=num()
while True:
print('=====欢迎进入学生管理系统=====\n1.登陆\n2.注册\n3.退出\n'+'='*30)
try:
with open('./user.json') as f:
users = json.load(f)
except:
with open('./user.json', 'w') as f:
str1 = json.dumps([])
f.write(str1)
with open('./manage.json') as f:
users = json.load(f)
order2=input()
if order2 == '3':
exit('退出学生管理系统')
if order2=='2':
user={}
user_id=input('输入账号:')
user_pw=input('输入密码:')
user['账号']=user_id
user['密码'] = user_pw
users.append(user)
with open('./user.json', 'w') as f:
str1 = json.dumps(users)
f.write(str1)
elif order2=='1':
user_id=input('输入账号:')
user_pw=input('输入密码:')
user_in={}
user_in['账号']=user_id
user_in['密码'] = user_pw
k=0
for index in range(len(users)):
if users[index]==user_in:
k+=1
if k==0:
n=0
for user in users:
if user['账号']==user_id:
n+=1
if n==0:
print('没有该用户,请从新输入!')
continue
else:
print('密码错误,请从新输入!')
continue
else:
break
else:
print('**请正确操作**')
continue
while True:
menu()
if order=='9':
exit('已退出学生管理系统')
elif order=='1':
while True:
add_student()
order1=back()
if order1=='1':
continue
elif order1=='2':
break
else:
print('**请正确操作**')
break
continue
elif order=='2':
while True:
find_student()
order1=back()
if order1=='1':
continue
elif order1=='2':
break
else:
print('**请正确操作**')
break
continue
elif order=='3':
while True:
del_student()
order1 = back()
if order1 == '1':
continue
elif order1 == '2':
break
else:
print('**请正确操作**')
break
continue
else:
print('**请正确操作**')
continue
学生管理系统
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...