当前位置:网站首页>(6) Design of student information management system
(6) Design of student information management system
2022-08-02 03:59:00 【stealth rookie】
目录
分析
需求分析
学生管理系统应该具备的功能:
1.添加学生及成绩信息
2.Save student information to a file
3.可以查询、修改和删除学生信息
4.根据学生成绩进行排序
5.统计学生总分
系统设计
函数设计
主函数设计
#主函数
def main():
while True:
menu()
choice=int(input('Please choose a number:'))
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:
inser() #录入信息
elif choice==2:
search() #查找信息
elif choice==3:
delete() #删除信息
elif choice==4:
modify() #修改信息
elif choice==5:
sort() #排序
elif choice==6:
total()
elif choice==7:
show()
#Below is a directory menu
def menu():
print('=====================学生管理系统======================')
print('-----------------------功能菜单------------------------')
print('\t\t\t\t\t\t1.录入学生信息')
print('\t\t\t\t\t\t2.查找学生信息')
print('\t\t\t\t\t\t3.删除学生信息')
print('\t\t\t\t\t\t4.修改学生信息')
print('\t\t\t\t\t\t5.排序')
print('\t\t\t\t\t\t6.统计学生总人数')
print('\t\t\t\t\t\t7.显示所有学生信息')
print('\t\t\t\t\t\t0.退出')
print('-----------------------------------------')
#Below is the function that will implement the functionality
def inser():
pass
def search():
pass
def delete():
pass
def modify():
pass
def sort():
pass
def total():
pass
def show():
pass
if __name__=='__main__': #Run as the main program
main()
录入学生信息功能
从控制台录入学生信息,and save them to disk files
def inser():
student_list=[]
while True:
id=input('请输入id(如1001):')
if not id:
break
name=input('请输入姓名:')
if not name:
break
try:
English=int(input('请输入英语成绩:'))
Math = int(input('请输入数学成绩:'))
Python = int(input('请输入Python成绩:'))
except:
print('输入无效,不是整数类型,请重新输入')
continue
#将录入的学生信息保存到字典中
student={'id':id,'name':name,'English':English,'Math':Math,'Python':Python}
#将学生信息添加到列表中
student_list.append(student)
answer=input('是否继续添加?y/n')
if answer=='y' or 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() #Get all the information given tostudent
for item in student:
d=dict(eval(item)) #遍历student,Convert the format to a dictionary,赋给d
if id!='': #判断id不为空
if d['id']==id: #判断d中idwith the previous inputid相等 Equal to add information to student_query列表中
student_query.append(d)
elif name!='':
if d['name']==name:
student_query.append(d)
#显示查询结果
show_student(student_query)
#清空列表
student_query.clear()
answer=input('是否要继续查询?y/n')
if answer=='y':
continue
else:
break
else:
print('暂未保存学生信息')
return
def show_student(lst): #A function that displays the result
if len(lst)==0:
print('没有查询到学生信息,无数据显示!!!')
return
#定义标题显示格式
format_title='{:^6}\t{:^12}\t{:^8}\t{:^10}\t{:^8}'
print(format_title.format('ID','姓名','英语成绩','数学成绩','python成绩'))
#定义内容显示格式
format_data='{:^6}\t{:^12}\t{:^8}\t{:^10}\t{:^8}'
for item in lst:
print(format_data.format(item.get('id'),
item.get('name'),
item.get('English'),
item.get('Math'),
item.get('Python'),
int(item.get('English'))+int(item.get('Math'))+int(item.get('Python'))
))
删除学生信息功能
def delete():
while True:
student_id=input('请输入要删除的学生id:')
if student_id!='':
if os.path.exists(filename): #Determine if the file exists on the diskfilename,需要导入一个os模块
with open(filename,'r',encoding='utf-8') as file: #打开文件
student_old=file.readlines() #读取所有信息,放到列表中
else: #If the file does not exist on disk,Define the list to be empty
student_old=[]
flag=False #标记是否删除
if student_old: #判断列表,为Ture就执行下面的语句
with open(filename,'w',encoding='utf-8') as wfile:
d={} #空字典,The dictionary after that will be deleted,write to disk file
for item in student_old:
d=dict(eval(item)) #将字符串转成字典
if d['id']!=student_id: #判断字典d中idwith the students who need to be removedid不同,Just write this information in
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): #判断文件是否存在,Read and put if it existsstudents——old,不存在就return结束函数
with open(filename,'r',encoding='utf-8') as rfile:
student_old=rfile.readlines()
else:
return
student_id=input('Please enter the student to be modifiedID:')
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: #The input process may have gone wrong,所以加上try...except
try:
d['name']=input('请输入姓名:') #根据键获取值,再修改
d['English'] = input('请输入英语成绩:')
d['Math'] = input('请输入数学成绩:')
d['Python'] = input('请输入python成绩:')
except:
print('输入有错,请重新输入!!')
else:
break
wfile.write(str(d)+'\n') #把字典转为str类型,Write new information to the file
print('修改成功')
else:
wfile.write(str(d)+'\n') #Not to be modified,write the information to the file
answer=input('是否继续修改其他学生信息?y/n:')
if answer=='y':
modify()
统计学生总人数
def total():
if os.path.exists(filename):
with open(filename,'r',encoding='utf-8') as rfile:
students=rfile.readlines()
if students:
print(f'一共有(len(students))名学生')
else:
print('还未录入学生信息')
else:
print('暂未保存数据信息')
显示所有学生信息功能
def show():
student_lst=[]
if os.path.exists(filename): #判断文件是否存在
with open(filename,'r',encoding='utf-8') as rfile:
students=rfile.readlines() #Open the file to read all the data
for item in students:
student_lst.append(eval(item))
if student_lst:
show_student(student_lst) #调用显示学生信息的方法,在前面定义过show_student()这个函数
else:
print('暂未保存过数据!!!')
排序模块设计
def sort():
show()
if os.path.exists(filename): #判断文件是否存在
with open(filename,'r',encoding='utf-8') as rfile: #打开文件,Read everything and put itstudent_lst
student_lst=rfile.readlines()
student_new=[] #新建空列表
for item in student_lst: #遍历student_lst内容,Convert to dictionary assignd,再将d内容放到student_new列表,[{},{},{}]
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() #调用这个函数,is to retype it again
mode=input('请选择排序方式(1.按英语成绩排序2.按数学成绩排序3.按python成绩排序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['Math']), reverse=asc_or_desc_bool)
elif mode=='3':
student_new.sort(key=lambda x: int(x['Python']), reverse=asc_or_desc_bool)
elif mode=='0':
student_new.sort(key=lambda x: int(x['English'])+int(x['Math'])+int(x['Python']), reverse=asc_or_desc_bool)
else:
print('您的输入有误,请重新输入!!')
sort()
show_student(student_new)
lambda是Python预留的关键字
lambda函数的特性:
1.lambda函数是匿名的:所谓匿名函数,通俗地说就是没有名字的函数.
2.lambda函数有输入和输出:输入是传入到参数列表argument_list的值,输出是根据表达式expression计算得到的值.
3.lambda函数一般功能简单:单行expression决定了lambda函数不可能完成复杂的逻辑,只能完成非常简单的功能.由于其实现的功能一目了然,甚至不需要专门的名字来说明.
lambda x, y : x+y
lambda 冒号前是参数,After the colon is the value returned by the expression.
x和y是函数的两个参数,冒号后面的表达式是函数的返回值
项目打包生成exe可执行文件
1.首先,打开自己要发布的工程 ,点击底部的“Terminal”打开终端,输入命令:
pip install pyinstaller ,按回车键运行.
2.输入命令:pyinstaller ,Press Enter to show that the installation was successful.
3.输入命令pyinstaller --console --onefile xxx.py
4. exe文件的路径
边栏推荐
猜你喜欢
CTF-网鼎杯往届题目
Phonebook
hackmyvm: controller walkthrough
PHP8.2 version release administrator and release plan
IO stream, encoding table, character stream, character buffer stream
(4) Function, Bug, Class and Object, Encapsulation, Inheritance, Polymorphism, Copy
hackmyvm-bunny walkthrough
(2) 顺序结构、对象的布尔值、选择结构、循环结构、列表、字典、元组、集合
(6) 学生信息管理系统设计
IO流、 编码表、 字符流、 字符缓冲流
随机推荐
[campo/random-user-agent]随机伪造你的User-Agent
宝塔邮局邮箱设置成功后能发送不能接收问题处理
PHP 发起支付宝支付时 订单信息乱码解决
QR code generation API interface, which can be directly connected as an A tag
Solve the problem of Zlibrary stuck/can't find the domain name/reached the limit, the latest address of Zlibrary
PHP8.2的版本发布管理员和发布计划
MySql高级 -- 约束
14.JS语句和注释,变量和数据类型
MOMENTUM: 2 vulnhub walkthrough
PHP有哪些杀手级超厉害框架或库或应用?
(7) 浅学 “爬虫” 过程 (概念+练习)
[mikehaertl/php-shellcommand] A library for invoking external command operations
Function hoisting and variable hoisting
Basic use of v-on, parameter passing, modifiers
PHP的几个有趣的打开方式:从基本到变态
Kali install IDEA
Masashi: 1 vulnhub walkthrough
PHP realizes the automatic reverse search prompt of the search box
ES6三点运算符、数组方法、字符串扩展方法
Using PHPMailer send mail