python学生信息管理系统实现代码

yipeiwu_com6年前Python基础

1.本人第一次学python做出来的,当时满满的成就感,当作纪念!!!!!

非常简单,复制即可使用

代码块

import json#把字符串类型的数据转换成Python基本数据类型或者将Python基本数据类型转换成字符串类型。 
def login_user():
 while True:
  register=input('学生姓名:')
  try:
   with open(register+'.json')as file_object:
    user_message=json.load(file_object)#json.load(obj) 读取文件中的字符串,序列化成Python的基本数据类型
  except FileNotFoundError:
   print('该用户不存在!')
   break
  else:
   print('_'*20)
   register_password = input('请输入学号:')
   if user_message['id']==register and user_message['password']==register_password:
    str_print = '姓名:{}\t数学成绩:{}\t语文成绩:{}\t英语成绩: {}'
    grade_list = []
    while 1:
     print('''******************************
       欢迎使用【学生信息管理系统】
       请选择你想要进行的操作
       1.新建学生信息
       2.显示全部信息
       3.查询学生信息
       4.删除学生信息
       5.修改学生信息
       0.退出系统
     ******************************''')
     action = input('请选择你想要的进行操作:\n')
     if action == '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))
      pass
     elif action == '2':
      '''显示全部信息'''
      for info in grade_list:
       print(str_print.format(*info))
     elif action == '3':
      '''查询学生信息'''
      name = input('请输入你需要查询学生的姓名:')
      for info in grade_list:
       if name in info:
        print(str_print.format(*info))
        break
       else:
        print('此学生不存在')
      
     elif action == '4':
      '''删除学生信息'''
      name = input('请输入你需要查询学生的姓名:')
      for info in grade_list:
       if name in info:
        info_=grade_list.pop(grade_list.index(info))
        print('这个学员的信息已经被删除\n',info_)
        break
       else:
        print('此学生不存在')
     elif action == '5':
      '''修改学生信息'''
      name = input('请输入你需要查询学生的姓名:')
      for info in grade_list:
       if name in info:
        index = grade_list.index(info)
        break
       else:
        print('此学生不存在')
        continue
      math = input('请输入数学成绩:')
      chinese = input('请输入语文成绩:')
      english = input('请输入英语成绩:')
      total = int(math) + int(chinese) + int(english)
      grade_list[index][0:] = [name,math,chinese,english,total]
      print('修改后的一个成绩',grade_list[index])
     elif action == '0':
      '''退出系统'''
      break
     else:
      print('输入信息有误,请重新输入')
    #print('登陆成功')
    return register,user_message
   else:
    print('登陆失败!用户名或密码错误')
    break

def register_user():
 new_user=input('增加学生姓名:')
 try:
  with open(new_user+',.jion','r') as file_object:
   pass
 except FileNotFoundError:
  new_password_one=input('请确认学号:')
  new_password_two=input('请再次确认学号:')
  if new_password_one==new_password_two:
   user_message={'id':new_user,'password':new_password_one}
   with open(new_user+'.json','w')as file_object:
    json.dump(user_message,file_object)#json.dump(obj) 将Python的基本数据类型序列化成字符串并写入到文件中
    print('新用户已经注册成功!可以登录了。')
  else:
   print('两次输入不一致')
 else:
  print('该用户已经存在')
while True:
 print('*'*50)
 print('*  1.登录用户   *')
 print('*       *')
 print('*  2.注册用户   *')
 print('*       *')
 print('*  3.退出    *')
 print('*'*50)
 test_content=input('请输入你的选项:')
 if test_content=='1':
  try:
   user_id,user_system=login_user()
   pass
  except TypeError:
   print('请重新输入')
  # print('登录用户!')
 elif test_content=='2':
  register_user()
  #print('注册用户')
 elif test_content=='3':
  
  
  print('退出系统')
  break
 else:
  print('非法输入字符')

        效果图(里面的全部功能都可以实现)

总结

以上所述是小编给大家介绍的python学生信息管理系统实现代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对【听图阁-专注于Python设计】网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!

相关文章

tensorflow 获取模型所有参数总和数量的方法

实例如下所示: from functools import reduce from operator import mul def get_num_params(): num_p...

python numpy元素的区间查找方法

找了半天,以为numpy的where函数像matlab 的find函数一样好用,能够返回一个区间内的元素索引位置。结果没有。。(也可能是我没找到) 故自己写一个函数,找多维数组下的,在某...

Python Django 页面上展示固定的页码数实现代码

Python Django 页面上展示固定的页码数实现代码

如果页数太多的话,全部显示在页面上就会显得很冗杂 可以在页面中显示规定的页码数 例如: book_list.html: <!DOCTYPE html> <htm...

教你使用python实现微信每天给女朋友说晚安

教你使用python实现微信每天给女朋友说晚安

本文为大家分享了教你用微信每天给女朋友说晚安的python实战,供大家参考,具体内容如下 但凡一件事,稍微有些重复。我就考虑怎么样用程序来实现它。 这里给各位程序员朋友分享如何每天给朋友...

详解Python的Django框架中的模版相关知识

HTML被直接硬编码在 Python 代码之中。 def current_datetime(request): now = datetime.datetime.now() h...