【博学谷学习记录】超强总结,用心分享 | 学生信息管理系统设计

【博学谷IT技术支持】

项目的流程设计

首先就是项目流程的设计,当然之所以这么搞跟需求是有一定关系的。

  • 初始化数据
  • 功能设计
    • 添加学生成绩
    • 修改学生成绩
    • 查询所有学生成绩
    • 查询学生不及格科目
    • 输出班级学生成绩单
    • 查询不同分段的学生信息
    • 退出系统

项目开发

初始化数据

首先说明下为什么要初始化数据,这里我们首先定义了数据格式。对于小白来讲可能这些东西对他们很复杂,但是对于有开发经验的我们,可能唯一需要考虑的只是SQL表的设计,但是为了方便,我们这里存储到本地。

数据格式的设计

首先思路学生的属性有哪些?学期,年级,班级,学号,姓名,各科成绩(例如):语文,数学,英语,python。

这里提取下学生的公共属性:例如学期,年级,班级等,剩下的基本都是属于学生本人的私有属性

grade_data = [] # 年级总数据
grade_info = {} # 年级信息

# 学期列表
semester_list = [
    {'key': '0', 'value': '第一学期'},
    {'key': '1', 'value': '第二学期'}
]
# 年级列表
grade_list = [
    {'key': '0', 'value': '小学一年级'},
    {'key': '1', 'value': '小学二年级'},
    {'key': '2', 'value': '小学三年级'}
]
# 班级列表
class_list = [
    {'key': '01', 'value': '01班'},
    {'key': '02', 'value': '02班'},
    {'key': '03', 'value': '03班'}
]
# 学生列表
student_list = [] 
# 学生对象
student_info = {}  

数据初始化

数据的存储文件为student_data.csv,文件的读取,python有内置函数open

# open有几个重要的参数,分别是文件名,打开模式(读,写,追加等)还有读取格式,
dataRead = open("student_data.csv", "r", encoding='utf-8')
content = dataRead.readline()
self.grade_data = eval(content)
dataRead.close()

添加学生成绩

添加学生成绩,这里其实也很好操作,首选我们选择学期,是上学期还是下学期,然后是年级一年级还是二年级,其次是班级是01班还是02班。当这些公共的基础信息填写完毕之后,那就是学生学号,姓名,成绩之类的信息了。在填写信息的时候,有一点需要注意,就是班级是否存在,如果存在的话需要将原来的数据添加当前学生列表中。同时添加结束后需要提问,是否需要继续添加。如果不需要的话就保存数据,需要的话就继续添加。

例子: 选择年级

for items in self.grade_list:
    print(items.get('key') + ':' + items.get('value'))
    
self.stu_grade = input('请选择年级: (例如:0 -- 小学一年级 )')

for items in self.grade_list:
    if items.get('key') == self.stu_grade:
        print('您选择的是:{}'.format(items.get('value')))
        print()

班级是否存在的判断


if class_exist == True:
   // 班级存在
   self.student_list.append(student_info)
   ....
else:
   // 班级不存在
   self.student_list = []
   .....

学生信息修改

学生信息修改,说明学生信息已经存在了,因为要通过公共信息选择,最后加学号查找,判断是否存在该学号,如果不存在需要再次输入,这里需要定义一个while True循环,同时在修改结束后后再次询问是否还要修改。

# 主要代码
while True:
    stu_num = input('请输入要修改成绩学生的学号:')
    search_state = False
    for temp in self.grade_data:
        if temp['stu_grade'] == self.stu_grade and temp['stu_semester'] == self.stu_semester and temp['stu_class'] == self.stu_class:
            print(temp['stu_grade'] + '-' + temp['stu_class'] + '-' + temp['stu_semester'])
            for temp_info in temp['student_list']:
                if temp_info['stu_num'] == stu_num:
                    search_state = True
                    print('已找到学生成绩:')
                    ......
                    break

    if search_state == False:
        print('该班级没有该学号,请重新输入!!!')
        continue

    alter_state = input('是否继续修改?Y/N')
    if alter_state == 'y' or alter_state == 'Y':
        continue
    else:
        break

查询所有学生成绩

当前需求比较简单,就是遍历是每个班的所有学生的成绩展示,同时可以计算下总成绩,还要平均分之类的,愿意的话还可以计算每科的及格率。这里只简单的计算了总成绩和平均分

for i in self.grade_data:
    if i['stu_grade'] == self.stu_grade and i['stu_semester'] == self.stu_semester and i['stu_class'] == self.stu_class:
        print(i['stu_grade'] + '-' + i['stu_class'] + '-' + i['stu_semester'])
        for temp_info in i['student_list']:
        ...遍历所有的数据.... 

总分 平均分计算

gross_score = int(list['stu_chinese']) \
              + int(list['stu_math']) \
              + int(list['stu_english']) \
              + int(list['stu_python'])
average_score = gross_score / 4

输出班级学生成绩单

按班级输出学生成绩单,循环遍历数据,根据年级,班级,还有各科成绩,输出最后结果

for i in self.class_list:
    if self.stu_class == i['key']:
        stu_class_name = i['value']
for temp in self.grade_data:
    if temp['stu_grade'] == self.stu_grade and temp['stu_semester'] == self.stu_semester and temp['stu_class'] == self.stu_class:
        print(temp['stu_grade'] + '-' + temp['stu_class'] + '-' + temp['stu_semester'])
        for temp_info in temp['student_list']:
            print('班级:{}  {}同学: 学号:{} 语文:{}分 数学:{}分 英语:{}分 python:{}分'.format(stu_class_name, temp_info['stu_name'], temp_info['stu_num'], temp_info['stu_chinese'], temp_info['stu_math'], temp_info['stu_english'], temp_info['stu_python']))

查询学生不及格科目

同样是一个简单的需求,遍历数据,如果存在不及格的科目就将科目及学生一起添加到失败的list里,如果没有不及格的科目就不输出

for temp_data in self.grade_data:
    stu_grade = temp_data['stu_grade']
    stu_semester = temp_data['stu_semester']
    stu_class = temp_data['stu_class']
    for temp in temp_data['student_list']:
        fail_info = {}
        .... 编写业务逻辑.....
        
        
        # 有不及格的科目输出该信息
        if fail_info.get('stu_chinese') or fail_info.get('stu_math') or fail_info.get('stu_english') or fail_info.get('stu_python'):
            print(fail_info)

查询不同分段的学生信息

这个需求也比较简单,还是遍历数据,同时计算下每个分段的学生成绩。定义多个数据,然后判断学生在哪个分段就填充到哪个列表中

list_60, list_79, list_89, list_90 = [], [], [], []
for temp_data in self.grade_data:
    for temp_info in temp_data['student_list']:
        gross_score, average_score = self.calculate_score(temp_info)
        if average_score >= 90:
            list_90.append(temp_info)
        if 80 <= average_score < 90:
            list_89.append(temp_info)
        if 60 <= average_score < 80:
            list_79.append(temp_info)
        if average_score < 60:
            list_60.append(temp_info)

print('平均分在90及以上的学生')
for temp_90 in list_90:
    ......
print('平均分在80-89的学生')
for temp_89 in list_89:
   ......
print('平均分在60-79的学生')
for temp_79 in list_79:
   
print('平均分在60分以下的学生')
for temp_60 in list_60:
    ......

退出系统

退出系统是最简答的,就是从循环跳出,给用户提示,当然,也要重复确认一下,省得错误退出。

总结

当前这个小作业,用到的都是python最基础的知识,暂时就先这么多,等有空了还可以再优化下,比如还可以添加一些管理班级,年级的方法,或者给一个静态页面等等!!!

posted @ 2023-03-20 00:15  牛牛牛牛牛牛牛牛  阅读(36)  评论(0编辑  收藏  举报