學生資訊管理系統的七大模塊
- 學生資訊管理系統基本理解
- 系統業務流程
- 系統開發環境
- 主函式數設計流程
- 由函式圖得出函式基本骨架
- 錄入學生資訊
- 業務流程
- 代碼如下
- 洗掉學生資訊
- 業務流程
- 代碼如下
- 修改學生資訊
- 業務流程圖
- 代碼如下
- 查找學生資訊功能
- 業務流程圖
- 代碼如下
- 統計學生總人數
- 業務流程圖
- 代碼如下
- 排序
- 業務流程圖
- 代碼如下
- 顯示所有學生資訊
- 業務圖
- 代碼如下
- 最后得出這個工程完整的代碼
學生資訊管理系統基本理解

系統業務流程

系統開發環境
·作業系統:Win10
·Python解釋器版本:Python3.8
·開發工具:PyCharm
·Python內置模塊:os,re
·系統主界面運行效果圖如下:

主函式數設計流程

由函式圖得出函式基本骨架
def main():
while True:
menm()
choice = int(input("請輸入"))
if choice in [0, 1, 2, 3, 4, 5, 6, 7]:
if choice == 0:
answer = input("您確定退出系統嗎?y/n")
if answer == "y" or answer == "Y":
print("謝謝使用")
break
else:
continue
elif choice == 1:
insert() # 錄入學生資訊
elif choice == 2:
search()
elif choice == 3:
delete()
elif choice == 4:
modify
elif choice == 5:
sort()
elif choice == 6:
total()
elif choice == 7:
show()
def menm():
print("=======================學生資訊管理系統=====================")
print("=======================功能選單===========================")
print("\t\t\t\t\t1.錄入學生資訊")
print("\t\t\t\t\t2.查找學生資訊")
print("\t\t\t\t\t3.洗掉學生資訊")
print("\t\t\t\t\t4.修改學生資訊")
print("\t\t\t\t\t5.排序")
print("\t\t\t\t\t6.統計學生總人數")
print("\t\t\t\t\t7.顯示所有學生資訊")
print("\t\t\t\t\t0.退出")
def insert():
pass
def search():
pass
def delete():
pass
def modify():
pass
def sort():
pass
def total():
pass
def show():
pass
if __name__ == "__main__":
main()
錄入學生資訊
業務流程

代碼如下
def insert():
student_list = []
while True:
id = input("請輸入id:")
if not id:
break
name = input("請輸入姓名:")
if not name:
break
try:
english = int(input("請輸入英語成績"))
python = int(input("請輸入python成績:"))
java = int(input("請輸入java成績:"))
except:
print("輸入無效,不是整數型別,請重新輸入:")
continue
# 將錄入的成績保存到字典中
student = {"id": id, "name": name, "english": english, "python": python, "java": java}
# 將學生資訊添加到串列中
student_list.append(student)
answer = input("是否繼續相加")
if answer == "y":
continue
else:
break
# 呼叫save函式
save(student_list)
print("學生資訊錄入完畢!!!!")
def save(lst):
try:
stu_txt = open(filename, "a", encoding="utf-8")
except:
stu_txt = open(filename, "w", encoding = "utf-8")
for item in lst:
stu_txt.write(str(item) + "\n")
stu_txt.close()
洗掉學生資訊
業務流程

代碼如下
def delete():
while True:
student_id=input("請輸入要洗掉學生的id:")
if student_id!="":
if os.path.exists(filename):
with open(filename,"r",encoding="utf-8")as file:
student_old=file.readlines()
else:
student_old=[]
flag=False #標記是否洗掉
if student_old:
with open(filename,"w",encoding="utf-8") as wfile:
d={}
for item in student_old:
d=dict(eval(item)) #將字串轉換為字典
if d["id"]!=student_id:
wfile.write(str(d)+"\n")
else:
flag=True
if flag:
print(f"id為{student_id}的學生資訊已被洗掉")
else:
print(f"沒有找到id為{student_id}的學生資訊")
else:
print("無學生資訊")
break
show() #洗掉之后要重新顯示學生資訊
answer=input("是否繼續洗掉?y/n")
if answer=="y":
continue
else:
break
修改學生資訊
業務流程圖

代碼如下
def modify():
show()
if os.path.exists(filename):
with open(filename,"r",encoding="utf-8") as rfile:
student_old=rfile.readlines()
else:
return
student_id=input("請輸入要修改學生的id:")
with open(filename,"w",encoding="utf-8") as wfile:
for item in student_old:
d=dict(eval(item))
if d["id"]==student_id:
print("找到學生資訊了,可以修改相關資訊了!")
while True:
try:
d["name"]=input("請輸入姓名:")
d["english"]=input("請輸入英語成績:")
d["python"]=input("請輸入Python成績:")
d["java"]=input("請輸入java成績:")
except:
print("您輸入有誤,請重新輸入!!!")
else:
break
wfile.write(str(d)+"\n")
print("修改成功!!!")
else:
wfile.write(str(d)+"\n")
answer=input("是否要繼續修改其他學生資訊?y/n")
if answer=="y":
modify()
查找學生資訊功能
業務流程圖

代碼如下
def search():
student_query = []
while True:
id = ""
name = ""
if os.path.exists(filename):
mode = input("按id查找請輸入1,按姓名查找請輸入2:")
if mode == "1":
id = input("請輸入學生id:")
elif mode == "2":
name = input("請輸入學生的姓名:")
else:
print("您的輸入有誤,請重新輸入")
search()
with open(filename, "r", encoding="utf-8") as rfile:
student = rfile.readlines()
for item in student:
d = dict(eval(item))
if id != "":
if d["id"] == id:
student_query.append(d)
elif name != "":
if d["name"] == name:
student_query.append(d)
# 顯示查詢結果
show_student(student_query)
# 清空串列
student_query.clear()
anser = input("是否要繼續查詢?y/n\n")
if anser == "y":
continue
else:
break
else:
print("暫未保存學員資訊")
return
def show_student(lst):
if len(lst) == 0:
print("沒查到學生資訊,無資料顯示!!!")
return
# 定義標準的顯示格式
format_title = "{:^6}\t{:^12}\t{:^8}\t{:^01}\t{:^10}\t{:^8}"
print(format_title.format("ID", "姓名", "英語成績","python成績", "java成績", "總成績"))
# 定義內容的顯示格式
format_data = "{:^6}\t{:^12}\t{:^8}\t{:^10}\t{:^10}\t{:^8}"
for item in lst:
print(format_data.format(item.get("id"),
item.get("name"),
item.get("english"),
item.get("python"),
item.get("java"),
int(item.get("english")) + int(item.get("python")) + int(item.get("java"))
))
統計學生總人數
業務流程圖

代碼如下
def total():
if os.path.exists(filename):
with open(filename,"r",encoding="utf-8") as rfile:
student=rfile.readlines()
if student:
print(f"一共有{len(student)}名學生")
else:
print("還沒有錄入學生資訊")
else:
print("暫未保存資料資訊.....")
排序
業務流程圖

代碼如下
def sort():
show()
if os.path.exists(filename):
with open(filename,"r",encoding="utf-8") as rfile:
student_list=rfile.readlines()
student_new=[]
for item in student_list:
d=dict(eval(item))
student_new.append(d)
else:
return
asc_or_desc=input("請選擇(0.升序 1.降序):")
if asc_or_desc=="0":
asc_or_desc_bool=False
elif asc_or_desc=="1":
asc_or_desc_bool=True
else:
print("您的輸入有誤,請重新輸入")
sort()
mode=input("請選擇排序方式(1,按英語成績排序 2,按python程式排序 3,按Java程式排序 0,按照總程式排序)")
if mode=="1":
student_new.sort(key=lambda x:int(x["english"]),reverse=asc_or_desc_bool)
elif mode=="2":
student_new.sort(key=lambda x:int(x["python"]),reverse=asc_or_desc_bool)
elif mode=="3":
student_new.sort(key=lambda x:int(x["java"]),reverse=asc_or_desc_bool)
elif mode=="0":
student_new.sort(key=lambda x: int(x["english"])+int(x["python"])+int(x["java"]),reverse=asc_or_desc_bool)
else:
print("您的輸入有誤,請從新輸入:")
sort()
show_student(student_new)
顯示所有學生資訊
業務圖

代碼如下
def show():
student_lst=[]
if os.path.exists(filename):
with open(filename,"r",encoding="utf-8") as rfile:
student=rfile.readlines()
for item in student:
student_lst.append(eval(item))
if student_lst:
show_student(student_lst)
else:
print("暫未保存過資料!!")
最后得出這個工程完整的代碼
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# author:杜小皮
# datetime:2021/1/30 10:12
# software: PyCharm
import os # 洗掉操作匯入os模塊
filename = "student.txt"
def main():
while True:
menm()
choice = int(input("請輸入"))
if choice in [0, 1, 2, 3, 4, 5, 6, 7]:
if choice == 0:
answer = input("您確定退出系統嗎?y/n")
if answer == "y" or answer == "Y":
print("謝謝使用")
break
else:
continue
elif choice == 1:
insert() # 錄入學生資訊
elif choice == 2:
search()
elif choice == 3:
delete()
elif choice == 4:
modify()
elif choice == 5:
sort()
elif choice == 6:
total()
elif choice == 7:
show()
def menm():
print("=======================學生資訊管理系統=====================")
print("=======================功能選單===========================")
print("\t\t\t\t\t1.錄入學生資訊")
print("\t\t\t\t\t2.查找學生資訊")
print("\t\t\t\t\t3.洗掉學生資訊")
print("\t\t\t\t\t4.修改學生資訊")
print("\t\t\t\t\t5.排序")
print("\t\t\t\t\t6.統計學生總人數")
print("\t\t\t\t\t7.顯示所有學生資訊")
print("\t\t\t\t\t0.退出")
def insert():
student_list = []
while True:
id = input("請輸入id:")
if not id:
break
name = input("請輸入姓名:")
if not name:
break
try:
english = int(input("請輸入英語成績"))
python = int(input("請輸入python成績:"))
java = int(input("請輸入java成績:"))
except:
print("輸入無效,不是整數型別,請重新輸入:")
continue
# 將錄入的成績保存到字典中
student = {"id": id, "name": name, "english": english, "python": python, "java": java}
# 將學生資訊添加到串列中
student_list.append(student)
answer = input("是否繼續相加")
if answer == "y":
continue
else:
break
# 呼叫save函式
save(student_list)
print("學生資訊錄入完畢!!!!")
def save(lst):
try:
stu_txt = open(filename, "a", encoding="utf-8")
except:
stu_txt = open(filename, "w", encoding="utf-8")
for item in lst:
stu_txt.write(str(item) + "\n")
stu_txt.close()
def search():
student_query = []
while True:
id = ""
name = ""
if os.path.exists(filename):
mode = input("按id查找請輸入1,按姓名查找請輸入2:")
if mode == "1":
id = input("請輸入學生id:")
elif mode == "2":
name = input("請輸入學生的姓名:")
else:
print("您的輸入有誤,請重新輸入")
search()
with open(filename, "r", encoding="utf-8") as rfile:
student = rfile.readlines()
for item in student:
d = dict(eval(item))
if id != "":
if d["id"] == id:
student_query.append(d)
elif name != "":
if d["name"] == name:
student_query.append(d)
# 顯示查詢結果
show_student(student_query)
# 清空串列
student_query.clear()
anser = input("是否要繼續查詢?y/n\n")
if anser == "y":
continue
else:
break
else:
print("暫未保存學員資訊")
return
def show_student(lst):
if len(lst) == 0:
print("沒查到學生資訊,無資料顯示!!!")
return
# 定義標準的顯示格式
format_title = "{:^6}\t{:^12}\t{:^8}\t{:^01}\t{:^10}\t{:^8}"
print(format_title.format("ID", "姓名", "英語成績","python成績", "java成績", "總成績"))
# 定義內容的顯示格式
format_data = "{:^6}\t{:^12}\t{:^8}\t{:^10}\t{:^10}\t{:^8}"
for item in lst:
print(format_data.format(item.get("id"),
item.get("name"),
item.get("english"),
item.get("python"),
item.get("java"),
int(item.get("english")) + int(item.get("python")) + int(item.get("java"))
))
def delete():
while True:
student_id = input("請輸入要洗掉學生的id:")
if student_id != "":
if os.path.exists(filename):
with open(filename, "r", encoding="utf-8")as file:
student_old = file.readlines()
else:
student_old = []
flag = False # 標記是否洗掉
if student_old:
with open(filename, "w", encoding="utf-8") as wfile:
d = {}
for item in student_old:
d = dict(eval(item)) # 將字串轉換為字典
if d["id"] != student_id:
wfile.write(str(d) + "\n")
else:
flag = True
if flag:
print(f"id為{student_id}的學生資訊已被洗掉")
else:
print(f"沒有找到id為{student_id}的學生資訊")
else:
print("無學生資訊")
break
show() # 洗掉之后要重新顯示學生資訊
answer = input("是否繼續洗掉?y/n")
if answer == "y":
continue
else:
break
def modify():
show()
if os.path.exists(filename):
with open(filename, "r", encoding="utf-8") as rfile:
student_old = rfile.readlines()
else:
return
student_id = input("請輸入要修改學生的id:")
with open(filename, "w", encoding="utf-8") as wfile:
for item in student_old:
d = dict(eval(item))
if d["id"] == student_id:
print("找到學生資訊了,可以修改相關資訊了!")
while True:
try:
d["name"] = input("請輸入姓名:")
d["english"] = input("請輸入英語成績:")
d["python"] = input("請輸入Python成績:")
d["java"] = input("請輸入java成績:")
except:
print("您輸入有誤,請重新輸入!!!")
else:
break
wfile.write(str(d) + "\n")
print("修改成功!!!")
else:
wfile.write(str(d) + "\n")
answer = input("是否要繼續修改其他學生資訊?y/n")
if answer == "y":
modify()
def sort():
show()
if os.path.exists(filename):
with open(filename,"r",encoding="utf-8") as rfile:
student_list=rfile.readlines()
student_new=[]
for item in student_list:
d=dict(eval(item))
student_new.append(d)
else:
return
asc_or_desc=input("請選擇(0.升序 1.降序):")
if asc_or_desc=="0":
asc_or_desc_bool=False
elif asc_or_desc=="1":
asc_or_desc_bool=True
else:
print("您的輸入有誤,請重新輸入")
sort()
mode=input("請選擇排序方式(1,按英語成績排序 2,按python程式排序 3,按Java程式排序 0,按照總程式排序)")
if mode=="1":
student_new.sort(key=lambda x:int(x["english"]),reverse=asc_or_desc_bool)
elif mode=="2":
student_new.sort(key=lambda x:int(x["python"]),reverse=asc_or_desc_bool)
elif mode=="3":
student_new.sort(key=lambda x:int(x["java"]),reverse=asc_or_desc_bool)
elif mode=="0":
student_new.sort(key=lambda x: int(x["english"])+int(x["python"])+int(x["java"]),reverse=asc_or_desc_bool)
else:
print("您的輸入有誤,請從新輸入:")
sort()
show_student(student_new)
def total():
if os.path.exists(filename):
with open(filename,"r",encoding="utf-8") as rfile:
student=rfile.readlines()
if student:
print(f"一共有{len(student)}名學生")
else:
print("還沒有錄入學生資訊")
else:
print("暫未保存資料資訊.....")
def show():
student_lst=[]
if os.path.exists(filename):
with open(filename,"r",encoding="utf-8") as rfile:
student=rfile.readlines()
for item in student:
student_lst.append(eval(item))
if student_lst:
show_student(student_lst)
else:
print("暫未保存過資料!!")
if __name__ == "__main__":
main()
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/356786.html
標籤:其他
下一篇:Postman變數的使用
