1. 程式人生 > 程式設計 >python學生資訊管理系統實現程式碼

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,total])
      print('姓名:{}\t數學成績:{}\t語文成績:{}\t英語成績: {}'.format(name,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,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學生資訊管理系統實現程式碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回覆大家的。在此也非常感謝大家對我們網站的支援!
如果你覺得本文對你有幫助,歡迎轉載,煩請註明出處,謝謝!