class manger

/ 默认分类 / 没有评论 / 494浏览
def addStudent():
     ‘添加学生’
    name = input("请输入学生的姓名:")
    age = input("请输入学生的年龄:")
    score = input("请输入学生的成绩:")
    return {"name":name,"age":age,"score":score}

def removeStudent(opt,student):
    """删除元素"""
    opt.remove(student)


def findStudent(opt):
    """查找学生"""
    name = input("请输入学生的姓名:")
    for student in opt:
        for key,value in student.items():
            if value == name:
                return student
def main():
    "初始化班级"
    cls =[{'name': '李四', 'age': '11', 'score': '88'}, {'name': '黄飞', 'age': '13', 'score': '64'}, {'name': '李红', 'age': '34', 'score': '78'}]
    i = 1
    while True:
        print("1:all student")
        print("2:add student")
        print("3:remove student")
        print("4:quit: quit")
        keys = input("请输入功能选项:")
        if "1" == keys:
           print(cls)
        elif "2" == keys:
           cls.append(addStudent())
           print(cls)
        elif "3" == keys:
            removeStudent(cls,findStudent(cls))
            print(cls)
        elif "quit" == quit:
            exit()
        else:
            print("输入错误")

if __name__ == '__main__':
   main()
评论已关闭.