美文网首页
2018-10-09简单的学生管理系统

2018-10-09简单的学生管理系统

作者: MW演员 | 来源:发表于2018-10-09 20:36 被阅读0次

    (学生管理系统简易版)

    用一个变量来保存一个班级的学生信息,学生信息包括:姓名、学号、成绩(英语、体育、美术、数学)、年龄

    • b.给这个班级添加学生
    • c.根据姓名查看班级里的某个学生的信息
    • d.根据姓名删除一个指定的学生信息
    • e.查看班级的所有的学生信息
    • f.求指定的学生平均成绩
    提示:用一个列表来存整个班级的学生信息;列表的每个元素是字典,来存储每个学生的信息
    def head():
        print('欢迎进入千峰学生管理系统')
        print('1.添加学生')
        print('2.查看所有学生信息')
        print('3.按姓名查询学生信息')
        print('4.求指定的学生平均成绩')
        print('5.删除学生')
        print('q.退出系统')
        print('>>>', end = '')
        return 0
    
    def add_student_information(stu_information):
        new_infomation = {}
        new_name = input('请输入学生姓名:')
        new_infomation['student_name'] = new_name
    
        new_age = int(input('请输入学生年龄:'))
        new_infomation['student_age'] = new_age
    
        new_num = input('请输入学生学号:')
        while True:
            flag4 = 0
            for item in stu_information:
                if item['student_num'] == new_num:
                    print('学号已经存在')
                    new_num = input('请重新输入学生学号:')
                else:
                    new_infomation['student_num'] = new_num
                    flag4 = 1
                    break
            if flag4:
                break
            else:
                continue
        new_math = int(input('请输入学生数学成绩:'))
        new_infomation['math'] = new_math
    
        new_english = int(input('请输入学生英语成绩:'))
        new_infomation['english'] = new_english
    
        new_art = int(input('请输入学生美术成绩:'))
        new_infomation['art'] = new_art
    
        new_IE = int(input('请输入学生体育成绩:'))
        new_infomation['IE'] = new_IE
        return new_infomation
    
    def find_student_information(stu_name,stu_class):
        for index in range(len(stu_class)):
            if stu_class[index]['student_name'] == stu_name:
                return index
                break
        else:
            return None
    
    def averge_score(num, stu_class):
        sum1 = 0
        for student in stu_class:
            if student['student_num'] == num:
                sum1 = student['math'] + student['art'] + student['IE'] + student['english']
                break
        average = sum1 / 4
        return average
    
    def drop_student_information(stu_num, stu_class):
        for index in range(len(stu_class)):
            if stu_class[index]['student_num'] == num:
                return index
                break
        else:
            return None
    
    student_class = [{'student_name': '张三', 'student_age': 18, 'student_num': '001', 'math': 85, 'english': 65, 'art': 94, 'IE': 85},
                     {'student_name': '王五', 'student_age': 20, 'student_num': '002', 'math': 87, 'english': 78, 'art': 60, 'IE': 80},
                     {'student_name': '李四', 'student_age': 9, 'student_num': '003', 'math': 85, 'english': 79, 'art': 90, 'IE': 94}
                     ]
    flag = 1
    
    while flag != 'q':
        head()
        flag = input()
        if flag == '1':
            student_class.append(add_student_information(student_class))
            print('添加成功!')
        elif flag == '2':
            for item in student_class:
                print(item)
        elif flag == '3':
            name = input('请输入需要查询的学生姓名:')
            i = find_student_information(name, student_class)
            if str(i).isnumeric():
                print(student_class[i])
            else:
                print('该学生不在该班级')
        elif flag == '4':
            num = input('请输入学生学号:')
            print('该生平均分:%.2f' % (averge_score(num, student_class)))
        elif flag == '5':
            num = input('请输入需要删除的学生学号:')
            i = drop_student_information(num, student_class)
            if str(i).isnumeric():
                del student_class[i]
                print('删除成功!')
            else:
                print('该生不在该班级')
        elif flag == 'q':
            break
    
    结果

    相关文章

      网友评论

          本文标题:2018-10-09简单的学生管理系统

          本文链接:https://www.haomeiwen.com/subject/hogyaftx.html