python創(chuàng)建學(xué)生成績(jī)管理系統(tǒng)
python學(xué)生成績(jī)管理系統(tǒng)創(chuàng)建,供大家參考,具體內(nèi)容如下
要求編寫學(xué)生類,班級(jí)類,并在電腦運(yùn)行生成表單,輸入一個(gè)數(shù)字,得到對(duì)應(yīng)的結(jié)果。
輸出樣式

代碼如下
學(xué)生類
class Student:
def __init__(self,sno,name,english,math):
self.sno=sno
self.name=name
self.__english=english
self.__math=math
@property
def english(self):
return self.__english
@english.setter
def english(self,english):
self.__english=english if 0<=english<=100 else 0
@property
def math(self):
return self.__math
@math.setter
def math(self,math):
self.__math=math if 0<=math<=100 else 0
def get_average(self):
return (self.english+self.math)/2
def __str__(self):
s=str.format('{0:>4d}{1: >4s}{2:>8d}{3:>8d}',self.sno,self.name,self.english,self.math)
return s
@staticmethod
def get_header():
return '{0:>2s}{1: >4s}{2:\u3000>4s}{3: >4s}'.format('學(xué)號(hào)','姓名','英語','數(shù)學(xué)')
def __eq__(self,other):
return self.sno==other.sno
def __gt__(self,other):
return self.sno>other.sno
測(cè)試
#測(cè)試 if __name__=='__main__': s1=Student(1,'王大海',100, 65) s2=Student(2,'李三',38,45) s3=Student(3,'李四',88,45) print(s1>s2) students=[s2,s1,s3] students.sort() print(students) print(Student.get_header()) for s in students: print(s)
結(jié)果

班級(jí)類
from student import Student
class BanJi:
def __init__(self,name):
self.name=name
self.students=[]
self.load_data()
def load_data(self):
with open('data.txt','r')as f:
for line in f:
d=line.split()
self.students.append(Student(int(d[0]),d[1],int(d[2]),int(d[3])))
def show_student(self):
print(Student.get_header())
for s in self.students:
print(s)
def add_student(self,student):
if student in self.students:
return '此學(xué)生已存在'
else:
self.students.append(student)
return'添加成功'
def __index_student(self,sno):
s=Student(sno,'',0,0)
if s not in self.students:
return None
else:
return self.students.index(s)
def find_student(self,sno):
i = self.__index_student(sno)
if i is None:
return None
else:
return self.students[i]
def delete_student(self,sno):
i = self.__index_student(sno)
if i is None:
r = '沒有學(xué)號(hào)為{0: d}'.format(sno)
else:
del self.students[i]
r = '刪除成功!'
return r
def update_student(self,sno):
s = self.find_student(sno)
if s is None:
return '沒有學(xué)號(hào)為{0:d}的學(xué)生!'.format(sno)
else:
print(s)
print('請(qǐng)輸入新的值,直接回車不修改!')
name_str = input('姓名:')
english_str = input('英語:')
math_str = input('數(shù)學(xué):')
s.name = name_str if len(name_str)>0 else s.name
s.name = int(english_str) if len(english_str)>0 else s.english
s.name = int(math_str) if len(math_str)>0 else s.math
return '修改成功!'
def save_data(self):
with open('data.txt','w',encoding = 'GBK') as f:
for s in self.students:
r = str.format('{0:d} {1:s} {2:d} {3:d}\n',s.sno,s.name,s.english,s.math)
f.write(r)
def sort_by_english(self,reverse = False):
self.students.sort(key=lambda x: x.english,reverse = reverse)
學(xué)生管理系統(tǒng)
import os
from student import Student
from banji import BanJi
menu = """
*********************
學(xué)生成績(jī)管理系統(tǒng)
1.瀏覽學(xué)生成績(jī)
2.按學(xué)號(hào)查找學(xué)生
3.按英語成績(jī)排序
4.添加學(xué)生
5.刪除學(xué)生
6.修改學(xué)生信息
9.保存
0.退出
*********************
"""
tip = '輸入(0-9)選擇操作:'
choice = ''
b = BanJi('1802')
os.system('cls')
print(menu)
while True:
choice = input(tip)
os.system('cls')
print(menu)
if choice == '0':
print('數(shù)據(jù)以保存!')
break
elif choice == '1':
b.show_student()
elif choice == '2':
sno = int(input('請(qǐng)輸入您需要查詢的學(xué)生的學(xué)號(hào):'))
s = b.find_student(sno)
if s is None:
print('無此學(xué)號(hào)的學(xué)生!')
else:
print(s)
elif choice == '3':
b.sort_by_english()
b.show_student()
elif choice == '4':
print('請(qǐng)輸入學(xué)生信息:')
sno = int(input('學(xué)號(hào):'))
name = input('姓名:')
english = int(input('英語:'))
math = int(input('數(shù)學(xué):'))
student = Student(sno,name,english,math)
r = b.add_student(student)
print(r)
elif choice == '5':
sno = int(input('請(qǐng)輸入要?jiǎng)h除的學(xué)生的學(xué)號(hào):'))
r = b.delete_student(sno)
print(r)
elif choice == '6':
sno = int(input('請(qǐng)輸入要修改的學(xué)生的學(xué)號(hào):'))
r = b.update_student(sno)
print(r)
elif choice == '9':
b.save_data()
print('保存成功!')
else:
print('輸入錯(cuò)誤!')
用spyder或者cmd運(yùn)行都可以。
更多學(xué)習(xí)資料請(qǐng)關(guān)注專題《管理系統(tǒng)開發(fā)》。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Scrapy爬蟲文件批量運(yùn)行的實(shí)現(xiàn)
這篇文章主要介紹了Scrapy爬蟲文件批量運(yùn)行的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-09-09
簡(jiǎn)單介紹Python的Tornado框架中的協(xié)程異步實(shí)現(xiàn)原理
這篇文章主要介紹了簡(jiǎn)單介紹Python的Tornado框架中的協(xié)程異步實(shí)現(xiàn)原理,作者基于Python的生成器講述了Tornado異步的特點(diǎn),需要的朋友可以參考下2015-04-04
Python實(shí)現(xiàn)按逗號(hào)分隔列表的方法
今天小編就為大家分享一篇Python實(shí)現(xiàn)按逗號(hào)分隔列表的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-10-10
Python Pickle 實(shí)現(xiàn)在同一個(gè)文件中序列化多個(gè)對(duì)象
今天小編就為大家分享一篇Python Pickle 實(shí)現(xiàn)在同一個(gè)文件中序列化多個(gè)對(duì)象,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-12-12
python實(shí)現(xiàn)地牢迷宮生成的完整步驟
這篇文章主要給大家介紹了關(guān)于python實(shí)現(xiàn)地牢迷宮生成的相關(guān)資料,文中通過示例代碼將實(shí)現(xiàn)的過程一步步介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2021-09-09
Python實(shí)現(xiàn)高效求解素?cái)?shù)代碼實(shí)例
這篇文章主要介紹了Python實(shí)現(xiàn)高效求解素?cái)?shù)代碼實(shí)例,本文直接給出代碼實(shí)例,需要的朋友可以參考下2015-06-06

