基本上这几块都是自己写出来的,功能实现上大体上问题都不大:
修改信息模块:
# 项目名:STUsys
# NAME:modify
# 开发时间:2021/4/26 13:18
#修改信息模块
import mainsystem,show
def modify():
while True:
target_id = input('请输入要修改的学生学号:')
with open(mainsystem.filename,'r',encoding='utf-8') as file:
student_list = file.readlines()
with open(mainsystem.filename,'w',encoding='utf-8') as wfile:
for student in student_list:
student_dict = dict(eval(student))
if target_id == student_dict.get('id'):
print('找到该学生信息如下:')
print(student_dict)
student_dict_old = student_dict
# print('id'.ljust(10, ' ') + '|', end='')
# print('name'.ljust(10, ' ') + '|', end='')
# print('chinese'.ljust(10, ' ') + '|', end='')
# print('math'.ljust(10, ' ') + '|', end='')
# print('english'.ljust(10, ' ') + '|')
# for item in student_dict:
# print(str(student_dict.get(item)).ljust(10, ' ') + '|', end='')
# break
print('请输入需要修改的信息:')
for item in student_dict:
value_new = input('请输入新的%s信息'%item)
student_dict[item] = value_new
print('修改后的信息为:%s'%str(student_dict))
choice_modify = input('请确认是否要修改信息?y/n')
if choice_modify == 'y' or choice_modify == 'Y':
wfile.write(str(student_dict)+'\n')
else:
wfile.write(str(student_dict_old)+'\n')
else:
wfile.write(str(student_dict)+'\n')
# else:
# print('未找到学生信息,请确认学号是否正确并重新输入')
show.show()
choice = input('是否要继续修改?y/n')
if choice == 'y' or choice == 'Y':
continue
else:
break
查找信息模块:
# 项目名:STUsys
# NAME:search
# 开发时间:2021/4/26 13:17
#查找信息模块
import mainsystem
def search():
while True:
target_id = input('请输入要查找的学生学号:')
with open(mainsystem.filename,'r',encoding='utf-8') as file:
student_list = file.readlines()
for student in student_list:
student_dict = dict(eval(student))
chinese = student_dict.get('chinese')
math = student_dict.get('math')
english = student_dict.get('english')
total = chinese + math + english
if target_id == student_dict.get('id'):
print('查找的学生信息如下:')
print('id'.ljust(10, ' ') + '|', end='')
print('name'.ljust(10, ' ') + '|', end='')
print('chinese'.ljust(10, ' ') + '|', end='')
print('math'.ljust(10, ' ') + '|', end='')
print('english'.ljust(10, ' ') + '|', end='')
print('total'.ljust(10, ' ') + '|')
for item in student_dict:
print(str(student_dict.get(item)).ljust(10, ' ') + '|', end='')
print(str(total).ljust(10, ' ') + '|')
break
else:
print('未找到学生信息,请确认学号是否正确并重新输入')
continue
choice = input('是否要继续查找?y/n')
if choice == 'y' or choice == 'Y':
continue
else:
break
所有学生信息模块:
# 项目名:STUsys
# NAME:show
# 开发时间:2021/4/26 13:20
#全部信息模块
import mainsystem
def show():
while True:
#将文件中的信息以列表形式读取出来
with open(mainsystem.filename,'r',encoding='utf-8') as file:
student_list = file.readlines()
pass
#判断取出的信息是否为空,为空提示无学生信息
if student_list == []:
print('404 Not Found')
else:
print('id'.ljust(10,' ')+'|',end='')
print('name'.ljust(10, ' ') + '|',end='')
print('chinese'.ljust(10, ' ') + '|',end='')
print('math'.ljust(10, ' ') + '|',end='')
print('english'.ljust(10, ' ') + '|',end='')
print('total'.ljust(10, ' ') + '|')
for student in student_list:
#在读取的列表中,每一行的学生信息为字符串类型,需要转换成字典类型
student_dict = dict(eval(student))
chinese = student_dict.get('chinese')
math = student_dict.get('math')
english = student_dict.get('english')
total = chinese + math + english
for item in student_dict:
print(str(student_dict.get(item)).ljust(10,' ')+'|',end='')
print(str(total).ljust(10,' ')+'|')
choice = input('是否要继续查看?y/n')
if choice == 'y' or choice == 'Y':
continue
else:
break
整体信息模块:
# 项目名:STUsys
# NAME:total
# 开发时间:2021/4/26 13:19
#总体信息模块
import mainsystem
def total():
while True:
# 将文件中的信息以列表形式读取出来
with open(mainsystem.filename, 'r', encoding='utf-8') as file:
student_list = file.readlines()
pass
# 判断取出的信息是否为空,为空提示无学生信息
if student_list == []:
print('404 Not Found')
else:
chinese_total = math_total = english_total = total_total = 0.0
for student in student_list:
# 在读取的列表中,每一行的学生信息为字符串类型,需要转换成字典类型
student_dict = dict(eval(student))
chinese = float(student_dict.get('chinese'))
math = float(student_dict.get('math'))
english = float(student_dict.get('english'))
total = float(chinese + math + english)
chinese_total = chinese_total + chinese
math_total = math_total + math
english_total = english_total + english
total_total = total_total + total
stu_num = len(student_list)
chinese_avg = chinese_total / stu_num
math_avg = math_total / stu_num
english_avg = english_total / stu_num
total_avg = total_total / stu_num
print('number'.ljust(10, ' ') + '|', end='')
print('CN avg'.ljust(10, ' ') + '|', end='')
print('math avg'.ljust(10, ' ') + '|', end='')
print('ENG avg'.ljust(10, ' ') + '|', end='')
print('total avg'.ljust(10, ' ') + '|')
print(str(stu_num).ljust(10, ' ') + '|', end='')
print(str(chinese_avg).ljust(10, ' ') + '|', end='')
print(str(math_avg).ljust(10, ' ') + '|', end='')
print(str(english_avg).ljust(10, ' ') + '|', end='')
print(str(total_avg).ljust(10, ' ') + '|')
choice = input('是否要继续查看?y/n')
if choice == 'y' or choice == 'Y':
continue
else:
break
排序这块我打算看下老师写的学习一下算法,上面这些我也还没看课程中写的咋样,看完之后如果有优化也一并在下一篇里一起写吧。