day13作业

'''author = 黄怀准'''
import filemanager
import studentManager

user_file = 'files/users.json'

def register():
while True:
user_name = input('请输入用户名(3~6位):')
if not 3 <= len(user_name) <= 6:
print('输入有误,请重新输入')
else:
break
password = input('请输入密码(6~12位):')
if not 6 <= len(password) <= 12:
print('输入有误,请重新输入')
else:
break
all_user = filemanager.read_text_file(user_file)
if user_name in all_user:
print('注册失败,账号已注册')
return
all_user[user_name] = password
filemanager.write_json_file(user_file, all_user)
print('注册成功!')
filemanager.write_json_file('files/'+user_name+'.json',{})

def login():
user_name = input('请输入用户名:')
password = input('请输入密码:')
all_user = filemanager.read_json_file(user_file)
if user_name not in all_user:
print('用户不存在!')
return
if all_user[user_name] == password:
print('登录成功!')
studentManager.user_name = user_name
studentManager.show_manage_page()
else:
print('登录失败!密码错误!')

def show_main_page():
page = filemanager.read_text_file('files/mainpage.txt')
while True:
print(page)
value = input('请输入1~3:')
if value == '1':
register()
elif value == '2':
login()
elif value == '3':
print('退出成功!')
return
else:
print('输入有误!请重新输入')

if name == 'main':
show_main_page()

'''author = 黄怀准'''
import filemanager

user_name = ''

def get_all_student():
user_message = filemanager.read_json_file('files/'+user_name+'.json')
all_student = user_message.get('all_student', [])
return all_student
def add_student():
while True:
stu_name = input('请输入学生姓名:')
stu_age = int(input('请输入学生年龄:'))
stu_tel = input('请输入学生电话')
user_message = filemanager.read_json_file('fiels/'+user_name+'.json')
all_student = user_message.get('all_student', [])
id_num = user_message.get('id_num', 0)
id_num += 1
stu_id = 'stu'+str(id_num).zfill(3)
stu = {'stu_id': stu_id, 'name': stu_name, 'age': stu_age, 'tel': stu_tel }
all_student.append(stu)
user_message['id_num'] = id_num
user_message['all_student'] = all_student
filemanager.write_json_file('files/'+user_name+'.json', user_message)

def find_student():
all_student = get_all_student()
if len(all_student) == 0:
print('无学生可管理!')
return
print('1.查看所有学生\n2.按姓名查找\n3.按学号查找4\nother.返回')
value = input('请选择:')
if value == '1':
for stu in all_student:
print(show_student_message(stu))
elif value == '2':
stu_name = input('学生姓名:')
flag = False
for stu in all_student:
if stu['name'] == stu_name:
print(show_student_message(stu))
flag = True
if not flag:
print('查无此生')
elif value =='3':
pass
else:
return

def show_manage_page():
page = filemanager.read_json_file('files/studentpage.txt')
while True:
print(page % user_name)
value = input('请输入1~5:')
if value == '1':
add_student()
elif value == '2':
find_student()
elif value == '3':
pass
modify_student()
elif value == '4':
pass
delete_student()
elif value == '5':
return
else:
print('输入有误!请重新输入!')

'''author = 黄怀准'''
import json

def read_json_file(file: str):
with open(file, 'r', encoding='utf-8') as f:
return json.loads(f.read())

def write_json_file(file: str, obj):
with open(file, 'w', encoding='utf-8') as f:
f.write(json.dumps(obj))

def read_text_file(file: str) -> str:
with open(file, 'r', encoding='utf-8') as f:
return f.read()

你可能感兴趣的:(day13作业)