美文网首页
day8-字典和集合-作业

day8-字典和集合-作业

作者: _桑心人 | 来源:发表于2018-10-09 20:54 被阅读0次

(学生管理系统简易版)
用一个变量来保存一个班级的学生信息,学生信息包括:姓名、学号、成绩(英语、体育、美术、数学)、年龄
b.给这个班级添加学生
c.根据姓名查看班级里的某个学生的信息
d.根据姓名删除一个指定的学生信息
e.查看班级的所有的学生信息
f.求指定的学生平均成绩

提示:用一个列表来存整个班级的学生信息;列表的每个元素是字典,来存储每个学生的信息

代码如下


"""
(学生管理系统简易版)
用一个变量来保存一个班级的学生信息,学生信息包括:姓名、学号、成绩(英语、体育、美术、数学)、年龄
b.给这个班级添加学生
c.根据姓名查看班级里的某个学生的信息
d.根据姓名删除一个指定的学生信息
e.查看班级的所有的学生信息
f.求指定的学生平均成绩
提示:用一个列表来存整个班级的学生信息;列表的每个元素是字典,来存储每个学生的信息
"""
student = []
while 1:
    print('欢迎来到学生管理系统')
    print('1.添加学生')
    print('2.查看某个学生信息')
    print('3.删除学生信息')
    print('4.查看班级所有学生信息')
    print('5.求指定的学生平均成绩')
    n = int(input('请选择:'))
    if n == 1:
        while 1:
            news = {}
            name = input('请输入学生信息:')
            age = input('请输入学生年龄:')
            tel = input('请输入学生电话号码:')
            # 英语、体育、美术、数学
            escore = int(input('请录入英语成绩:'))
            pscore = int(input('请录入体育成绩:'))
            ascore = int(input('请录入美术成绩:'))
            mscore = int(input('请录入数学成绩:'))
            news['name'] = name
            news['age'] = age
            news['tel'] = tel
            news['escore'] = escore
            news['pscore'] = pscore
            news['ascore'] = ascore
            news['mscore'] = mscore
            student.append(news)
            print('姓名|年龄|电话号码|英语|体育|美术|数学')
            for students in student:
                print(students['name'], students['age'], students['tel'], students['escore'], students['pscore'], students['ascore'], students['mscore'])
            print('添加成功!')
            print('1.继续添加')
            print('0.返回菜单')
            n = int(input('请选择:'))
            if n == 0:
                break
    elif n == 2:
        while 1:
            name = input('请输入你要查找的学生的姓名:')
            for students in student:
                if students['name'] == name:
                    print('学生信息为:')
                    print('姓名|年龄|电话号码|英语|体育|美术|数学')
                    print(students['name'], students['age'], students['tel'], students['escore'],
                    students['pscore'], students['ascore'], students['mscore'])
                else:
                    print('没有你要查找的人!')
            print('1.继续查找')
            print('0.返回菜单')
            n = int(input('请选择:'))
            if n == 0:
                break
    elif n == 3:
        while 1:
            name = input('请输入你要删除的学生的姓名:')
            for students in student:
                print('姓名|年龄|电话号码|英语|体育|美术|数学')
                if students['name'] == name:
                    print(students['name'], students['age'], students['tel'], students['escore'],
                          students['pscore'], students['ascore'], students['mscore'])
                    print('是否确认删除? 1.是 2.否')
                    n = int(input('请选择:'))
                    if n == 1:
                        student.remove(students)
                        print("删除成功!")
                else:
                    print('没有你要查找的人!')
            print('1.继续查找')
            print('0.返回菜单')
            n = int(input('请选择:'))
            if n == 0:
                break
    elif n == 4:
        while 1:
            print('全班学生信息:')
            print('姓名|年龄|电话号码|英语|体育|美术|数学')
            for students in student:
                print(students['name'], students['age'], students['tel'], students['escore'],
                      students['pscore'], students['ascore'], students['mscore'])
            print('0.返回菜单')
            n = int(input('请输入:'))
            if n == 0:
                break
    elif n == 5:
        name = input('请输入你要求成绩的学生的姓名:')
        for students in student:
            if students['name'] == name:
                print('学生信息为:')
                print('姓名|年龄|电话号码|英语|体育|美术|数学')
                for students in student:
                    print(students['name'], students['age'], students['tel'], students['escore'], students['pscore'],
                          students['ascore'], students['mscore'])
                sum1 = 0
                sum1 = students['escore'] + students['pscore'] + students['ascore'] + students['mscore']
                avg = sum1 / 4
                print('此学生的平均成绩为:', avg)
            else:
                print('没有你要查找的人!')
        print('1.继续求平均值')
        print('0.返回菜单')
        n = int(input('请选择:'))
        if n == 0:
            break

(不完善)运行结果大家自己下去实验!

相关文章

  • day8-字典和集合-作业

    (学生管理系统简易版)用一个变量来保存一个班级的学生信息,学生信息包括:姓名、学号、成绩(英语、体育、美术、数学)...

  • day8-字典和集合

    1.元组 1.什么是元组 示例 注意: (1).如果元组的元素只有一个的时候,必须在元素的后面加逗号 代码示例 运...

  • day8-字典和集合

    一、元组 1.什么是元组 使用()将多个元素括起来,多个元素之间用逗号隔开。a.容器,可以同时存储多个数据,不可变...

  • day8-元祖,字典和集合

    一、元祖 1.基本概念 定义:容器,可以同时存储多个数据,不可变的(不能进行增删改),有序的(可以通过下标获取元素...

  • Day8-元组,字典和集合

    一、认识类型 二、增删改查 注意: 字典的查询: a.字典[key] ---> 获取key对应的值(key值必须...

  • day8-元组、字典、集合作业

    1.声明一个字典保存一个学生的信息,学生信息中包括: 姓名、年龄、成绩(单科)、电话 2.声明一个列表,在列表中保...

  • day8-元组、字典、集合

    元祖 1.什么是元祖(tuple)容器型数据类型;不可变(不支持增删改)、有序(支持下标操作)将小括号作为容器的标...

  • 作业006:字典和集合

    **1.声明一个字典保存一个学生的信息,学生信息中包括: 姓名、年龄、成绩(单科)、电话、性别(男、女、不明) 2...

  • 2. 字典和集合

    字典和集合相比于列表和元组,字典和集合的性能更优:主要体现在查找、增加和删除操作; 1. 字典和集合基础 字典是一...

  • 6 字典和集合——《Swift3.0从入门到出家》原创连载

    6 字典和集合——《Swift3.0从入门到出家》 字典和集合 字典 字典是集合类型存放多个键值对,其中键是唯一的...

网友评论

      本文标题:day8-字典和集合-作业

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