Python實(shí)現(xiàn)學(xué)生管理系統(tǒng)(面向?qū)ο蟀?
本文實(shí)例為大家分享了Python實(shí)現(xiàn)學(xué)生管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
實(shí)現(xiàn)從面向過(guò)程到面向?qū)ο蟮倪^(guò)度,通過(guò)更改前面的學(xué)生管理系統(tǒng)實(shí)現(xiàn)面向?qū)ο?,也證明了面向過(guò)程可以完美過(guò)度到面向?qū)ο?,從而為以后的程序進(jìn)步做了進(jìn)一步優(yōu)化,方便以后的程序更改。
完整代碼如下:
student_main模塊中的代碼
import student_tools
class Student(student_tools.StudentT):
def __init__(self):
self.user=['wangtaotao']
self.pwd=['123456']
student_tools.StudentT.__init__(self)
#登錄
def denglu(self):
users = input("請(qǐng)輸入您的用戶名:")
pwds = input("請(qǐng)輸入您的密碼:")
if users in self.user and pwds in self.pwd:
self.student()
else:
print("賬號(hào)或密碼不正確,請(qǐng)重新輸入")
#注冊(cè)
def zhuce(self):
users=input("請(qǐng)輸入您要注冊(cè)的用戶名:")
pwds=input("請(qǐng)輸入您要注冊(cè)的密碼:")
self.user.append(users)
self.pwd.append(pwds)
print()
print("注冊(cè)成功!")
print()
#登錄界面
def dljiemian(self):
while True:
print("---------------------------")
print(" 學(xué)生管理系統(tǒng)登陸界面 V1.0 ")
print(" ")
print(" 1:登 錄 ")
print(" 2:注 冊(cè) ")
print(" 3:退 出 ")
print(" ")
print("---------------------------")
xx=input("請(qǐng)輸入您的選擇:")
#1.登錄
if xx=='1':
self.denglu()
elif xx=='2':
#2.注冊(cè)
self.zhuce()
elif xx=='3':
#3.退出
print()
print("成功退出!")
print()
break
else:
print("輸入錯(cuò)誤,請(qǐng)重新輸入")
#學(xué)生管理系統(tǒng)
def student(self):
# 調(diào)用student_tools模塊中的讀取文件函數(shù)
super().read_file()
while True:
#調(diào)用student_tools模塊中的界面函數(shù)
super().jiemian()
x=input("請(qǐng)輸入您的選擇:")
#添加學(xué)生
if x=='1':
super().add()
#刪除學(xué)生
elif x=='2':
super().dele()
#修改學(xué)生
elif x=='3':
super().xiugai()
#查詢學(xué)生
elif x=='4':
super().find()
#顯示所有學(xué)生
elif x=='5':
super().showall()
#保存數(shù)據(jù)至文件中
elif x=='6':
super().save_file()
#退出學(xué)生管理系統(tǒng),返回上一層登錄界面系統(tǒng)
elif x=='7':
print()
print("成功退出學(xué)生管理系統(tǒng)!")
break
else:
print()
print("輸入錯(cuò)誤,請(qǐng)重新輸入")
print()
#調(diào)用最先執(zhí)行的登錄界面函數(shù)
if __name__=='__main__':
wtt=Student()
wtt.dljiemian()
student_tools模塊中的代碼
import os
class StudentT(object):
def __init__(self):
self.student_list=[]
self.student_dict={}
#學(xué)生管理系統(tǒng)界面
@staticmethod
def jiemian():
print("---------------------------")
print(" 學(xué)生管理系統(tǒng) V1.0")
print(" ")
print(" 1:添加學(xué)生" )
print(" 2:刪除學(xué)生" )
print(" 3:修改學(xué)生" )
print(" 4:查詢學(xué)生" )
print(" 5:顯示所有學(xué)生" )
print(" 6:保存數(shù)據(jù)" )
print(" 7:退出系統(tǒng)" )
print(" ")
print("---------------------------")
#添加學(xué)生
def add(self):
name=input("請(qǐng)輸入錄入學(xué)生姓名:")
cls=input("請(qǐng)輸入學(xué)生班級(jí):")
age=input("請(qǐng)輸入錄入學(xué)生年齡:")
phone=input("請(qǐng)輸入錄入學(xué)生手機(jī)號(hào):")
addr=input("請(qǐng)輸入錄入學(xué)生家庭住址:")
self.student_dict={"name":name,"class":cls,"age":age,"phone":phone,"address":addr}
self.student_list.append(self.student_dict)
print()
print("-----添加學(xué)生信息界面-----")
print()
print("姓名\t\t","班級(jí)\t\t","年齡\t\t","電話號(hào)\t\t","家庭住址\t\t")
for student_dict_1 in self.student_list:
print("%s\t\t%s\t\t%s\t\t%s\t\t%s" %(student_dict_1["name"],
student_dict_1["class"],
student_dict_1["age"],
student_dict_1["phone"],
student_dict_1["address"]))
print()
print("錄入成功!")
print()
#刪除學(xué)生
def dele(self):
name_del=input("請(qǐng)輸入想要?jiǎng)h除的學(xué)生姓名:")
for student_dict_1 in self.student_list:
if name_del in student_dict_1["name"]:
self.student_list.remove(student_dict_1)
print()
print("刪除%s信息成功!" % name_del)
print()
break
else:
print()
print("您輸入的學(xué)生姓名錯(cuò)誤,請(qǐng)重新輸入")
print()
#修改學(xué)生
def xiugai(self):
name_xiugai=input("請(qǐng)輸入想要修改的學(xué)生姓名:")
for student_dict_1 in self.student_list:
if name_xiugai == student_dict_1["name"]:
print()
print("-----修改界面-----")
print()
print("姓名\t\t", "班級(jí)\t\t", "年齡\t\t", "電話號(hào)\t\t", "家庭住址\t\t")
print("%s\t\t%s\t\t%s\t\t%s\t\t%s" %(student_dict_1["name"],
student_dict_1["class"],
student_dict_1["age"],
student_dict_1["phone"],
student_dict_1["address"]))
#回車不修改
student_dict_1["name"]=self.new_input(student_dict_1["name"],"請(qǐng)輸入修改后的學(xué)生姓名[回車不修改]:")
student_dict_1["class"]=self.new_input(student_dict_1["class"],"請(qǐng)輸入修改后的學(xué)生班級(jí)[回車不修改]:")
student_dict_1["age"]=self.new_input(student_dict_1["age"],"請(qǐng)輸入修改后的學(xué)生年齡[回車不修改]:")
student_dict_1["phone"]=self.new_input(student_dict_1["phone"],"請(qǐng)輸入修改后的學(xué)生手機(jī)號(hào)[回車不修改]:")
student_dict_1["address"]=self.new_input(student_dict_1["address"],"請(qǐng)輸入修改后的學(xué)生家庭地址[回車不修改]:")
print()
print("修改成功!")
print()
break
else:
print()
print("您輸入的學(xué)生姓名錯(cuò)誤,請(qǐng)重新輸入")
print()
#查找學(xué)生
def find(self):
find_name=input("請(qǐng)輸入需要查找的學(xué)生姓名:")
for student_dict_1 in self.student_list:
if find_name == student_dict_1["name"]:
print()
print("-----查詢結(jié)果界面-----")
print()
print("姓名\t\t", "班級(jí)\t\t", "年齡\t\t", "電話號(hào)\t\t", "家庭住址\t\t")
print("%s\t\t%s\t\t%s\t\t%s\t\t%s" % (student_dict_1["name"],
student_dict_1["class"],
student_dict_1["age"],
student_dict_1["phone"],
student_dict_1["address"]))
else:
print()
print("-----查詢結(jié)果界面-----")
print()
print("無(wú)此學(xué)生信息")
#顯示所有學(xué)生信息
def showall(self):
if len(self.student_list)>0:
print()
print("-----顯示所有學(xué)生信息-----")
print()
print("姓名\t\t", "班級(jí)\t\t", "年齡\t\t", "電話號(hào)\t\t", "家庭住址\t\t")
for student_dict_1 in self.student_list:
print("%s\t\t%s\t\t%s\t\t%s\t\t%s" % (student_dict_1["name"],
student_dict_1["class"],
student_dict_1["age"],
student_dict_1["phone"],
student_dict_1["address"]))
else:
print()
print("暫無(wú)數(shù)據(jù)!")
print()
#設(shè)置用戶不輸入內(nèi)容返回原值,輸入內(nèi)容返回新內(nèi)容
def new_input(self,yuanzhi,message):
self.input_str=input(message)
if len(self.input_str)>0:
return self.input_str
else:
return yuanzhi
#保存數(shù)據(jù)至文件中
def save_file(self):
f = open("student2.txt", 'w', encoding='utf-8')
f.write(str(self.student_list))
f.close()
print("數(shù)據(jù)保存至student1.txt文件成功!")
#將數(shù)據(jù)讀取至變量中
def read_file(self):
if os.path.exists('student2.txt'):
f = open('student2.txt', 'r', encoding='utf-8')
ret = f.read()
self.student_list=eval(ret)
f.close()
print("數(shù)據(jù)讀取成功!")
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- python版學(xué)生管理系統(tǒng)
- python實(shí)現(xiàn)學(xué)生管理系統(tǒng)
- python學(xué)生管理系統(tǒng)代碼實(shí)現(xiàn)
- 基于python實(shí)現(xiàn)學(xué)生管理系統(tǒng)
- 詳解用python實(shí)現(xiàn)基本的學(xué)生管理系統(tǒng)(文件存儲(chǔ)版)(python3)
- 用python實(shí)現(xiàn)學(xué)生管理系統(tǒng)
- 基于Python實(shí)現(xiàn)簡(jiǎn)單學(xué)生管理系統(tǒng)
- Python實(shí)現(xiàn)學(xué)生管理系統(tǒng)的完整代碼(面向?qū)ο?
- python實(shí)現(xiàn)學(xué)生管理系統(tǒng)源碼
- 手把手教你做python學(xué)生管理系統(tǒng)
相關(guān)文章
使用Python爬蟲(chóng)庫(kù)BeautifulSoup遍歷文檔樹(shù)并對(duì)標(biāo)簽進(jìn)行操作詳解
今天為大家介紹下Python爬蟲(chóng)庫(kù)BeautifulSoup遍歷文檔樹(shù)并對(duì)標(biāo)簽進(jìn)行操作的詳細(xì)方法與函數(shù)2020-01-01
淺析AST抽象語(yǔ)法樹(shù)及Python代碼實(shí)現(xiàn)
Abstract Syntax Tree抽象語(yǔ)法樹(shù)簡(jiǎn)寫(xiě)為ATS,是相當(dāng)于用樹(shù)結(jié)構(gòu)將代碼程式表現(xiàn)出來(lái)的一種數(shù)據(jù)結(jié)構(gòu),這里我們就來(lái)淺析AST抽象語(yǔ)法樹(shù)及Python代碼實(shí)現(xiàn)2016-06-06
使用Python和OpenCV檢測(cè)圖像中的物體并將物體裁剪下來(lái)
這篇文章主要介紹了使用Python和OpenCV檢測(cè)圖像中的物體并將物體裁剪下來(lái),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-10-10
python將一個(gè)英文語(yǔ)句以單詞為單位逆序排放的方法
今天小編就為大家分享一篇python將一個(gè)英文語(yǔ)句以單詞為單位逆序排放的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-12-12
pycharm安裝django框架詳細(xì)圖文教程(指定版本)
這篇文章主要給大家介紹了關(guān)于pycharm安裝django框架(指定版本)的相關(guān)資料,PyCharm是一種Python?IDE,帶有一整套可以幫助用戶在使用Python語(yǔ)言開(kāi)發(fā)時(shí)提高其效率的工具,需要的朋友可以參考下2023-10-10
Python?中strip()函數(shù)詳細(xì)說(shuō)明及使用方法
strip()函數(shù)是Python字符串方法之一,用于處理字符串的前導(dǎo)和尾隨空白字符,它返回一個(gè)新字符串,該字符串是原始字符串去除前導(dǎo)和尾隨空格(包括空格、制表符、換行符等)后的結(jié)果,這篇文章主要介紹了Python?中strip()函數(shù)詳細(xì)說(shuō)明及使用方法,需要的朋友可以參考下2024-02-02
Python 3.6 -win64環(huán)境安裝PIL模塊的教程
PIL功能非常強(qiáng)大,但API卻非常簡(jiǎn)單易用。這篇文章主要介紹了Python 3.6 -win64環(huán)境安裝PIL模塊的教程,需要的朋友可以參考下2019-06-06
python使用Pyinstaller如何打包整個(gè)項(xiàng)目
這篇文章主要介紹了python使用Pyinstaller如何打包整個(gè)項(xiàng)目,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-11-11

