1.第一次学习python做的。当时满满的成就感,留个纪念吧!!!!!很简单,只需要复制代码块importjson#,将字符串类型的数据转换成Python基本数据类型,或者将Python基本数据类型转换成字符串类型即可。deflogin_user():whileTrue:register=input('学生姓名:')try:withopen(register+'.json')asfile_object:user_message=json.load(file_object)#json.load(obj)读取文件的字符串中的string被序列化为Python的基本数据类型exceptFileNotFoundError:print('用户不存在!')breakelse:print('_'*20)register_password=input('请输入学号:')ifuser_message['id']==registeranduser_message['password']==register_password:str_print='姓名:{}\t数学成绩:{}\t语文成绩:{}\t英语成绩:{}'grade_list=[]while1:print('''*********************************欢迎使用【学生信息管理系统】请选择操作1.新建学生信息2.显示所有信息3.查询学生信息4.删除学生信息5.修改学生信息0.退出系统**********************************''')action=input('请选择您要操作的内容:\n')ifaction=='1':'''新生信息'''name=input('请输入姓名')math=input('请输入数学成绩')chinese=input('请输入中文成绩')english=input('请输入英文成绩')total=int(math)+int(chinese)+int(english)grade_list.append([name,math,chinese,english,total])print([name,math,chinese,english,total])print('姓名:{}\t数学成绩:{}\t语文成绩:{}\t英语成绩:{}'.format(name,math,chinese,english,total))passelifaction=='2':'''显示所有信息'''forinfoingrade_list:print(str_print.format(*info))elifaction=='3':'''查询学生信息'''name=input('请输入需要查询的学生姓名:')forinfoingrade_list:ifnameininfo:print(str_print.format(*info))breakelse:print('该学生不存在')elifaction=='4':'''删除学生信息'''name=input('请输入需要查询的学生姓名Name:')forinfoingrade_list:ifnameininfo:info_=grade_list.pop(grade_list.index(info))print('该学生信息已删除\n',info_)breakelse:print('该学生不存在')elifaction=='5':'''修改学生信息'''name=input('请输入需要查询的学生姓名:')forinfoingrade_list:ifnameininfo:index=grade_list.index(info)breakelse:print('该学生不存在')continuemath=input('请输入数学成绩:')chinese=input('请输入中文成绩:')english=input('请输入英文成绩:')total=int(math)+int(chinese)+int(english)grade_list[index][0:]=[name,math,chinese,english,total]print('Arevisedgrade',grade_list[index])elifaction=='0':'''退出系统'''breakelse:print('输入信息错误,请重新输入')#print('登录成功')returnregister,user_messageelse:print('登录失败!用户名或密码错误')breakdefregister_user():new_user=input('Addstudentname:')try:withopen(new_user+',.jion','r')asfile_object:passexceptFileNotFoundError:new_password_one=input('请确认学号:')new_password_two=input('请再次确认学号:')ifnew_password_one==new_password_two:user_message={'id':new_user,'password':new_password_one}withopen(new_user+'.json','w')asfile_object:json.dump(user_message,file_object)#json.dump(obj)将Python的基本数据类型序列化为字符串写入文件中print('新用户注册成功!你可以登录')else:print('两次输入不一致')else:print('该用户已经存在')whileTrue:print('*'*50)print('*1.登录用户*')print('**')print('*2.注册用户*')print('**')print('*3.退出*')print('*'*50)test_content=input('请输入你的选项:')iftest_content=='1':try:user_id,user_system=login_user()passexceptTypeError:print('Pleasere-enter')#print('Loginuser!')eliftest_content=='2':register_user()#print('注册用户')eliftest_content=='3':print('退出系统')breakelse:print('非法输入字符')
