'''
Author:刘毅
time:2022/10/12 16:18'
键盘敲烂,月入过万
'''
from second_week import students_info
def select_(): #选项
print(' ♦ 1.注 册')
print(' ♦ 2.登 录')
print(' ♦ 3.注 销')
print(' ♦ 4.退 出')
print(' ♦ 5.管理员查询')
print('============================')
def register(): # 注册
user=input('请输入账号:')
password= input('请输入密码:')
dict1 = {'user': user, 'password': password}
try:
f = open('files/test01.txt', 'r', encoding='utf-8')
except FileNotFoundError:
all_ = []
else:
all_ = eval(f.read())
f.close()
for i in all_:
if i['user']==user:
print('账号输入重复,请重新输入')
break
else:
all_.append(dict1)
f = open('files/test01.txt','wt',encoding='utf-8')
f.write(str(all_))
f.close()
def login(): #登录
user = input('请输入账号:')
password = input('请输入密码:')
f = open('files/test01.txt', 'r', encoding='utf-8')
list1=eval(f.read())
f.close()
for i in list1:
if i['user']==user:
if i['password']==password:
print('登陆成功')
students_info.main()
return True
else:
print('账号或密码错误')
def logout(): #注销
user = input('请输入需要注销的账号:')
password = input('请输入需要注销的账户的密码:')
f = open('files/test01.txt', 'r', encoding='utf-8')
all_=eval(f.read())
for i in all_:
if i['user'] == user:
if i['password'] == password:
print('您输入的账号存在,立即执行注销操作')
all_.remove(i)
f = open('files/test01.txt', 'wt', encoding='utf-8')
f.write(str(all_))
f.close()
print('您输入的账号已注销!!!!')
break
else:
print('账号或密码错误')
return
def query():
m=input('请输入管理员密码:')
if m =='123456':
f = open('files/test01.txt', 'r', encoding='utf-8')
result=eval(f.read())
print(result)
else:
print('管理员密码输入错误,请重新输入!')
while True:
select_()
n=input('请输入数字选项:')
if n=='1':
register()
elif n=='2':
result = login()
if result == True:
break
elif n == '3':
logout()
elif n=='4':
print('退出系统')
break
elif n == '5':
query()
else:
print('您输入错误,请重新输入')
学生系统模块:
'''
Author:刘毅
time:2022/9/28 19:07'
键盘敲烂,月入过万
'''
# 定义一个函数
def gender_judge(gender):
if gender != '男' and gender != '女':
print('性别输入错误,请重新输入!')
return -1
def info_add():
studentID=input('请输入学号:')
name=input('请输入姓名:')
age=int(input('请输入年龄:'))
gender=input('请输入性别:')
if gender_judge(gender)==-1:
return
f=open('files/test.txt','r',encoding='utf-8')
global info
info=eval(f.read())
f.close()
for i in info:
if studentID==i['studentID']:
print('该学号的学生已存在,请勿重复添加学生信息')
return
info.append({'studentID':studentID,'name':name,'age':age,'gender':gender})
f = open('files/test.txt', 'w', encoding='utf-8')
f.write(str(info))
print(info)
def info_delete():
while True:
studentID=input('请输入您要删除学生的学号:')
f = open('files/test.txt', 'r', encoding='utf-8')
info = eval(f.read())
f.close()
for i in info:
if studentID==i['studentID']:
info.remove(i)
print('恭喜您删除成功')
f = open('files/test.txt', 'w', encoding='utf-8')
f.write(str(info))
f.close()
return
else:
print('您要删除的学号不在系统中,请重新输入')
def info_revise():
global info
while True:
studentID = input('请输入您要修改学生的学号:')
f = open('files/test.txt', 'r', encoding='utf-8')
info = eval(f.read())
f.close()
for i in info:
if studentID == i['studentID']:
print('已查询到该学号的信息,信息为:')
print(i)
while True:
print('1,修改姓名')
print('2,修改年龄')
print('3,修改性别')
print('4,退出修改')
select=input('请输入您要修改的选项:')
if select=='1':
name=input('您要将姓名更改为:')
i['name']=name
f = open('files/test.txt', 'w', encoding='utf-8')
f.write(str(info))
f.close()
elif select=='2':
age = input('您要将年龄更改为:')
i['age'] = age
f = open('files/test.txt', 'w', encoding='utf-8')
f.write(str(info))
f.close()
elif select=='3':
gender = input('您要将性别更改为:')
if gender_judge(gender) == -1:
break
i['gender'] = gender
f = open('files/test.txt', 'w', encoding='utf-8')
f.write(str(info))
f.close()
elif select == '4':
return
else:
print('选项输入错误,请重新输入!')
def inq_select():
global info
print('1,根据学号查询')
print('2,根据姓名查询')
print('3,根据年龄查询')
print('4,根据性别查询')
print('5,退出查询')
select = input('请输入以上选项:')
if select == '1':
studentID = input('请输入学号:')
f = open('files/test.txt', 'r', encoding='utf-8')
info = eval(f.read())
f.close()
for i in info:
if studentID == i['studentID']:
print(i)
elif select == '2':
name = input('请输入姓名:')
f = open('files/test.txt', 'r', encoding='utf-8')
info = eval(f.read())
f.close()
for i in info:
if name == i['name']:
print(i)
elif select == '3':
age = int(input('请输入年龄:'))
f = open('files/test.txt', 'r', encoding='utf-8')
info = eval(f.read())
f.close()
for i in info:
if age == i['age']:
print(i)
elif select == '4':
gender = input('请输入性别:')
if gender_judge(gender) == -2:
return
f = open('files/test.txt', 'r', encoding='utf-8')
info = eval(f.read())
f.close()
for i in info:
if gender == i['gender']:
print(i)
elif select == '5':
return -2
else:
print('选项输入错误,请重新输入!')
def info_inquire():
global info
while True:
rseult = inq_select()
if rseult==-2:
print('====退出了!=====')
return
def info_show():
f = open('files/test.txt', 'r', encoding='utf-8')
info = eval(f.read())
f.close()
print(info)
def info_print():
print('--------请选择功能-----')
print('1、添加学生')
print('2、删除学生')
print('3、修改学生')
print('4、查询学生')
print('5、显示所有学生')
print('6、退出系统')
print('-' * 20)
def main():
# 等待存储所有学生的信息
info = []
while True:
info_print()
n=eval(input('请输入数字选项:'))
if n==1:
info_add()
elif n==2:
info_delete()
elif n==3:
info_revise()
elif n==4:
info_inquire()
elif n==5:
info_show()
elif n==6:
print('退出学生管理系统')
break
else:
print('您输入错误,请重新输入')