python版學生管理系統(tǒng)
寫一個學生管理系統(tǒng),最好用python。
我都沒學過python呢,只好開始臨時抱佛腳,再到網(wǎng)上找找有沒有例子看看,下面是我參照另一個博主寫的,中間有一些和我不能融合的錯誤,我已經(jīng)解決了。
input("\n\nPress the enter key to exit.") def functionList(): # 定義功能菜單 print("---------請輸入序號選擇您要得功能---------") print("") print("-" * 14 + "1.查看學生信息" + "-" * 14) print("-" * 42) print("-" * 14 + "2.增加學生信息" + "-" * 14) print("-" * 42) print("-" * 14 + "3.刪除學生信息" + "-" * 14) print("-" * 42) print("-" * 14 + "4.修改學生信息" + "-" * 14) print("-" * 42) print("-" * 14 + "5.查找系統(tǒng)學生" + "-" * 14) print("-" * 42) print("-" * 14 + "6.返回到上一級" + "-" * 14) print("-" * 42) print("-" * 14 + "7.退出學生系統(tǒng)" + "-" * 14) print("") def functionList2(): # 定義簡單版功能菜單 print("---1:查看----2:增加-----3:刪除----4:修改----") print("-------5:查找-------6:返回------7:退出------") def sexInputDebug(sexInput): # 檢查性別輸入是否正確 if len(sexInput) == 1 and (sexInput.lower() == "m" or sexInput.lower() == "f"): return True else: return False def ageInputDebug(ageInput): # 檢查年齡輸入是否正確 if len(ageInput) == 2 and ageInput.isdigit() == True: return True else: return False def IDInputDebug(IDInput): # 檢查學號輸入是否正確 if len(IDInput) == 8 and IDInput.isdigit() == True: return True else: return False def nameListFunction(): # 顯示單個學生姓名信息 nameList = [] for i in range(len(studentList)): if studentList[i]["name"] not in nameList: nameList.append(studentList[i]["name"]) return nameList def findNameLocation(studentname): # 通過名字找到學生位置 for j in range(len(studentList)): if studentList[j]["name"] == studentname: return j def listFunction(): # 定義顯示現(xiàn)有學生信息函數(shù) for i in range(len(studentList)): studentInfo = studentList[i] print("姓名:%s--性別:%s--年齡:%s--學號:%s--備注:%s--" % ( studentInfo["name"], studentInfo["sex"], studentInfo["age"], studentInfo["studentID"], studentInfo["extra"])) print("") def addFunction(): # 定義增加學生函數(shù) while True: numInput =input("-----修改已經(jīng)存在的學生備注請輸入1\n-----------增加一個新的學生請輸入2:") if numInput == "2": while True: nameNoExistAdd = input("請輸入您要增加的名字:") nameList = nameListFunction() if nameNoExistAdd in nameList: print("%s在學生管理系統(tǒng)中已經(jīng)存在" % nameNoExistAdd) print("") else: newStudent = {} newStudent["name"] = nameNoExistAdd while True: sexInput = input("----請輸入%s的性別--f:man--m:women:" % nameNoExistAdd) if sexInputDebug(sexInput) == True: newStudent["sex"] = sexInput break else: print("輸入有誤,請重新輸入!") while True: ageInput = input("-------請輸入%s2位數(shù)字表示的年齡:" % nameNoExistAdd) if ageInputDebug(ageInput) == True: newStudent["age"] = ageInput break else: print("輸入有誤,請重新輸入!") while True: IDInput = input("----------請輸入%s的8位學號:" % nameNoExistAdd) if IDInputDebug(IDInput) == True: newStudent["studentID"] = IDInput break else: print("輸入有誤,請重新輸入!") extraInput = input("----------請輸入%s的備注:" % nameNoExistAdd) newStudent["extra"] = extraInput studentList.append(newStudent) print("--------------%s已經(jīng)添加到學生管理系統(tǒng)" % nameNoExistAdd) print("") print("姓名:%s--性別:%s--年齡:%s--學號:%s--備注:%s--" % ( newStudent["name"], newStudent["sex"], newStudent["age"], newStudent["studentID"], newStudent["extra"])) break break elif numInput == "1": while True: nameExistAdd = input("------請輸入您要修改備注的學生的名字:") nameList = nameListFunction() if nameExistAdd in nameList: extraExistAdd = input("-----------------請輸入您要添加的備注:") j = findNameLocation(nameExistAdd) studentList[j]["extra"] = extraExistAdd print("---------------備注已經(jīng)添加--------------") print("") print("姓名:%s--性別:%s--年齡:%s--學號:%s--備注:%s--" % ( studentList[j]["name"], studentList[j]["sex"], studentList[j]["age"], studentList[j]["studentID"], studentList[j]["extra"])) print("") break else: print("-----------------您輸入的姓名不存在") break else: print("----------------您輸入的信息不正確") def delFunction(): # 定義刪除學生的函數(shù) while True: nameDel = input("---------------請輸入您要刪除的名字:") studentNameList = nameListFunction() if nameDel in studentNameList: j = findNameLocation(nameDel) del studentList[j] print("-------------%s已經(jīng)從學生管理系統(tǒng)中刪除" % nameDel) print("") break else: print("------------------您要刪除的名字不存在!") def modifiFunction(): # 定義修改學生的函數(shù) while True: nameModifi = input("----------------請輸入要修改的名字:") studentNameList = nameListFunction() if nameModifi in studentNameList: print("------------請選擇要修改的內(nèi)容-----------") print("--------------1:修改姓名---------------") print("--------------2:修改性別---------------") print("--------------3:修改年齡---------------") print("--------------4:修改學號---------------") print("--------------5:修改備注---------------") while True: choiceInput = input("請輸入:") if choiceInput == "1": newNameInput = input("----------請輸入新的姓名:") j = findNameLocation(nameModifi) studentList[j]["name"] = newNameInput print("------------姓名已經(jīng)更新------------") print("") break elif choiceInput == "2": while True: newSexInput = input("----請輸入新的性別--f:man--m:women---") if sexInputDebug(newSexInput) == True: j = findNameLocation(nameModifi) studentList[j]["sex"] = newSexInput print("-------------性別已經(jīng)更新-------------") print("") break else: print("---------輸入有誤,請重新輸入!---------") break elif choiceInput == "3": while True: newAgeInput = input("----------請輸入新的年齡:") if ageInputDebug(newAgeInput) == True: j = findNameLocation(nameModifi) studentList[j]["age"] = newAgeInput print("------------年齡已經(jīng)更新------------") print("") break else: print("----------入有誤,請重新輸入!-------") break elif choiceInput == "4": while True: newIDInput = input("----------請輸入新的學號:") if IDInputDebug(newIDInput) == True: j = findNameLocation(nameModifi) studentList[j]["studentID"] = newIDInput print("------------學號已經(jīng)更新------------") print("") break else: print("----------入有誤,請重新輸入!-------") break elif choiceInput == "5": newExtraInput = input("----------請輸入新的備注:") j = findNameLocation(nameModifi) studentList[j]["extra"] = newExtraInput print("------------備注已經(jīng)更新------------") print("") break else: print("---------輸入有誤,請重新輸入!-------") print("") break else: print("-----------------您輸入的名字不存在!") print("") def searchFunction(): # 定義搜索學生的函數(shù) nameSearch = input("-------------請輸入要查找的名字:") print("") nameList = nameListFunction() if nameSearch in nameList: print("-----------------%s在學生管理系統(tǒng)中-------------------" % nameSearch) print("") j = findNameLocation(nameSearch) print("姓名:%s--性別:%s--年齡:%s--學號:%s--備注:%s--" % ( studentList[j]["name"], studentList[j]["sex"], studentList[j]["age"], studentList[j]["studenID"], studentList[j]["extra"])) print("") else: print("----------------%s不在學生管理系統(tǒng)中-----------------" % nameSearch) print("") # 默認學生信息系統(tǒng)內(nèi)容 studentList = [{"name": "Frank", "sex": "f", "age": 33, "studentID": "312312", "extra": ""}, {"name": "Jane", "sex": "m", "age": 45, "studentID": "324235", "extra": ""}] # 函數(shù)主體 print("-" * 11 + "歡迎來到學生管理系統(tǒng)" + "-" * 11) print("") print("") functionList() while True: # 進入循環(huán),根據(jù)序號選擇操作 userInput = input("----------------請輸入您要選擇的功能序號:") print("") if userInput == "1": # 顯示現(xiàn)有學生和返回 listFunction() functionList2() continue elif userInput == "2": # 使用增加函數(shù)和返回 addFunction() functionList2() continue elif userInput == "3": # 使用刪除函數(shù)和返回 delFunction() functionList2() continue elif userInput == "4": # 使用修改函數(shù)和返回 modifiFunction() functionList2() continue elif userInput == "5": # 使用搜索函數(shù)和返回 searchFunction() functionList2() continue elif userInput == "6": # 返回功能列表 functionList() continue elif userInput == "7": # 退出 break else: print("----------輸入有誤,請重新輸入!----------")
以下就是運行后的結(jié)果:
具體內(nèi)容實現(xiàn)我還要研究研究,不過這個代碼親測已經(jīng)可以運行了,小伙伴可以copy了。
過程中遇到的問題:
1. raw_input:我用的是3x的pyCharm,和2x的區(qū)別就在于不識別 raw_input,而要使用input。
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
- python實現(xiàn)學生管理系統(tǒng)
- python學生管理系統(tǒng)代碼實現(xiàn)
- 基于python實現(xiàn)學生管理系統(tǒng)
- 詳解用python實現(xiàn)基本的學生管理系統(tǒng)(文件存儲版)(python3)
- 用python實現(xiàn)學生管理系統(tǒng)
- 基于Python實現(xiàn)簡單學生管理系統(tǒng)
- Python實現(xiàn)學生管理系統(tǒng)的完整代碼(面向?qū)ο?
- python實現(xiàn)學生管理系統(tǒng)源碼
- Python實現(xiàn)學生管理系統(tǒng)(面向?qū)ο蟀?
- 手把手教你做python學生管理系統(tǒng)
相關(guān)文章
PyTorch 如何將CIFAR100數(shù)據(jù)按類標歸類保存
這篇文章主要介紹了PyTorch 將CIFAR100數(shù)據(jù)按類標歸類保存的操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2021-05-05python?pip安裝庫下載源更換(清華源、阿里源、中科大源、豆瓣源)
為了提高Python包的下載速度和穩(wěn)定性,可以配置國內(nèi)的鏡像源,如清華源、阿里源、中科大源和豆瓣源,設(shè)置方法簡單,只需更改pip的配置文件或使用命令行即可,需要的朋友可以參考下2024-10-10python re正則表達式模塊(Regular Expression)
Python 的 re 模塊(Regular Expression 正則表達式)提供各種正則表達式的匹配操作,在文本解析、復雜字符串分析和信息提取時是一個非常有用的工具.2014-07-07python3定位并識別圖片驗證碼實現(xiàn)自動登錄功能
這篇文章主要介紹了python3定位并識別圖片驗證碼實現(xiàn)自動登錄功能,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-01-01使用python將mysql數(shù)據(jù)庫的數(shù)據(jù)轉(zhuǎn)換為json數(shù)據(jù)的方法
這篇文章主要介紹了使用python將mysql數(shù)據(jù)庫的數(shù)據(jù)轉(zhuǎn)換為json數(shù)據(jù)的方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-07-07數(shù)據(jù)可視化Pyecharts的實際使用方式
這篇文章主要介紹了數(shù)據(jù)可視化Pyecharts的實際使用方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-04-04