老师为什么会多输出一个None呢
相关截图
# coding-utf-8 """ 学生信息库 """ students = { 1: { 'name': 'dewei', 'age': '33', 'class_number': 'A', 'sex': 'boy' }, 2: { 'name': '小慕', 'age': 18, 'class_number': 'B', 'sex': 'boy' }, 3: { 'name': '小曼', 'age': 18, 'class_number': 'A', 'sex': 'girl' }, 4: { 'name': '小高', 'age': 18, 'class_number': 'C', 'sex': 'boy', }, 5: { 'name': '小云', 'age': 18, 'class_number': 'B', 'sex': 'girl' } } def check_user_info(**kwargs): if 'name' not in kwargs: return '没有发现学生姓名' if 'age' not in kwargs: return '缺少学生年龄' if 'class_number' not in kwargs: return '缺少学生班级' if 'sex' not in kwargs: return '缺少学生性别' return True def get_all_students(): for id_, value in students.items(): print('学号:{},姓名:{},年龄:{},班级:{}'.format( id_, value['name'], value['age'], value['class_number'], value['sex'] )) return students # result = get_all_students() # print(result) def add_student(**kwargs): check = check_user_info(**kwargs) if not check: print(check) return id_ = max(students) + 1 students[id_] = { 'name': kwargs['name'], 'age': kwargs['age'], 'class_number': kwargs['class_number'], 'sex': kwargs['sex'] } # get_all_students() def delete_student(student_id): if student_id not in students: print('{}并不存在'.format(student_id)) else: user_info = students.pop(student_id) print('学号{},{}同学已经被删除了'.format(student_id, user_info['name'])) # delete_student(1) # add_student(name='小白',age = 19, class_number='A', sex='girl') # get_all_students() def update_student(student_id, **kwargs): if student_id not in students: print('并不存在这个学号:{}'.format(student_id)) check = check_user_info(**kwargs) if check != True: print(check) return students[student_id] = kwargs print('同学信息更新完毕') # update_student(1, name='dewei.zhang', age=33, class_number='A', sex='boy') # get_all_students() def get_user_by_id(student_id): return students.get(student_id) def search_users(**kwargs): values = list(students.values()) key = None value = None result = [] if 'name' in kwargs: key = 'name' value = kwargs[key] elif 'sex' in kwargs: key = 'sex' values = kwargs[key] elif 'age' in kwargs: key = 'age' value = kwargs[key] elif 'class_number' in kwargs: key = 'class_number' value = kwargs[key] else: print('没有发现搜索的关键字') # for user in values: # if user[key] == value: # result.append(user) # return result print(search_users(age1=18))
7
收起
正在回答 回答被采纳积分+1
1回答
Python全能工程师
- 参与学习 人
- 提交作业 16233 份
- 解答问题 4470 个
全新版本覆盖5大热门就业方向:Web全栈、爬虫、数据分析、软件测试、人工智能,零基础进击Python全能型工程师,从大厂挑人到我挑大厂,诱人薪资在前方!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星