用Python實現學生管理系統

2021-08-30 06:35:39 字數 2964 閱讀 4227

實現簡單的學生管理系統

import os,pickle

stu_dic = {}

filename = 'stu_inf.txt'

class student():

def __init__(self,name,age,stu_id,gender):

self.name = name

self.age = age

self.stu_id = stu_id

self.gender = gender

def show_stuinfo(self):

print('姓名: 年齡: 學號: 性別:'

.format(self.name,self.age,self.stu_id,self.gender))

class manasys():

def __init__(self,version):

self.version = version

def showmenu(self):

print('1.新增學生資訊')

print('2.查詢學生資訊')

print('3.修改學生資訊')

print('4.刪除學生資訊')

print('5.展示學生資訊')

print('6.退出系統')

def addstu(self,student):

stu_dic[student.name] = student

print('學生資訊新增成功')

def searchstu(self,name):

if name in stu_dic:

print('該名的學生資訊是:')

stu_dic[name].show_stuinfo()

else:

print('沒有該名學生資訊')

def updatestu(self,name):

if name in stu_dic:

alter_name = input('請輸入修改後的學生姓名:')

alter_age = input('請輸入修改後的學生年齡:')

alter_stu_id = input('請輸入修改後的學生學號:')

alter_gender = stu_dic[name].gender

stu_dic.pop(name)

stu_dic[alter_name] = student(alter_name,alter_age,alter_stu_id,alter_gender)

print('修改後的學生資訊是:')

stu_dic[alter_name].show_stuinfo()

else:

print('沒有該名學生資訊')

def delstu(self,name):

if name in stu_dic:

stu_dic.pop(name)

print('該名學生的資訊刪除成功')

else:

print('沒有該名學生資訊')

def showstu(self):

if len(stu_dic) > 0:

print('學生資訊如下:')

for stu_list in stu_dic.values():

stu_list.show_stuinfo()

else:

print('沒有學生資訊')

def exitsys(self):

print('謝謝訪問')

self.writedata(filename)

exit()

def writedata(self,filename):

f = open(filename,mode='wb')

pickle.dump(stu_dic,f)

f.close()

def loaddata(self,filename):

if os.path.exists(filename):

f = open(filename,mode='rb')

global stu_dic

stu_dic = pickle.load(f)

f.close()

manage_sys = manasys('v2.0')

manage_sys.loaddata(filename)

while true:

manage_sys.showmenu()

choice = input('請輸入你選擇的功能1-6:')

if choice == '1':

name = input('請輸入學生姓名:')

age = input('請輸入學生年齡:')

stu_id = input('請輸入學生學號:')

gender = input('請輸入學生性別:')

student = student(name,age,stu_id,gender)

manage_sys.addstu(student)

elif choice == '2':

name = input('請輸入要查詢的學生姓名:')

manage_sys.searchstu(name)

elif choice == '3':

name = input('請輸入要修改的學生姓名:')

manage_sys.updatestu(name)

elif choice == '4':

name = input('請輸入要刪除的學生姓名:')

manage_sys.delstu(name)

elif choice == '5':

manage_sys.showstu()

elif choice == '6':

manage_sys.exitsys()

else:

print('輸入有誤,請重新輸入')

Python實現學生管理系統

from prettytable import prettytable class studentinfo def init self print print 學生管理系統 v1.0 print 1 新增學生 print 2 顯示所有學生 print 3 查詢學生 print 4 修改學生 prin...

python實現學生管理系統開發

更多程式設計教程請到 菜鳥教程 說明 1 本學生管理系統非常非常簡易,只有增,顯,查,刪,改功能,對於python新手容易看懂上手。2 資訊的儲存只使用了字典和列表。3 不喜勿噴。1 主迴圈框架 while true print info str action input 請輸入想要進行的操作 if...

使用Python實現 學生學籍管理系統

該 主體由五個函式組成 1.add stu 新增 2.del stu 刪除 3.print stu 列印 4.exit stu 退出 5.system 主函式 1.add stu 此段函式作用 把輸入的值存入字典newstu中,並將字典存入列表stu中 def add stu newstu stu....