python学生信息管理系统——面向函数
【摘要】 面向函数的学生信息管理系统
# coding:utf-8
# @Author;dx
# @Time:2023-4-20
# @File:3.py
"""
学生信息管理系统
"""
print('欢迎使用学生信息管理系统~>_<~')
students = {
1: {
'name': 'xiaoshu',
'age': 18,
'class_number': 6,
'sex': 'female'
},
2: {
'name': 'xiaoding',
'age': 19,
'class_number': 6,
'sex': 'male'
}
}
def get_all_students():
for _id, value in students.items():
print('学号{},姓名{},年龄{},班级{},性别{}'.format(_id, value['name'], value['age'], value['class_number'],
value['sex']))
return students
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 add_students(**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']
}
return _id
def delete_students(students_id):
if students_id not in students:
print('{}不存在'.format(students_id))
else:
deleted_students = students.pop(students_id)
print('学号为{}, 姓名为{}的学生已删除'.format(students_id, deleted_students['name']))
def update_students(students_id, **kwargs):
if students_id not in students:
print('不存在这个学号')
return
check = check_user_info(**kwargs)
if not check:
print(check)
return
students[students_id] = kwargs
print('学生信息更新完毕!')
def get_user_by_id(students_id):
return students.get(students_id)
def search_students(**kwargs):
values = list(students.values())
key = None
value = None
result = []
if 'name' in kwargs:
key = 'name'
value = kwargs[key]
elif 'age' in kwargs:
key = 'age'
value = kwargs[key]
elif 'class_number' in kwargs:
key = 'class_number'
value = kwargs[key]
elif 'sex' in kwargs:
key = 'sex'
value = kwargs[key]
else:
print('没有发现搜索的关键词')
return
for user in values:
if user[key] == value:
result.append(user)
return result
while True:
print('--' * 20)
print('请选择服务:')
print('1.查看学生信息')
print('2.添加学生信息')
print('3.修改学生信息')
print('4.删除学生信息')
print('5.退出学生信息管理系统')
choose = int(input('请输入服务序号:'))
if choose == 1:
get_all_students()
print('--' * 20)
if choose == 2:
name1 = input('请输入要添加的学生姓名:')
age1 = int(input('请输入学生年龄:'))
class_number1 = int(input('请输入学生班级:'))
sex1 = input('请输入学生性别(male/famale):')
add_students(name=name1, age=age1, class_number=class_number1, sex=sex1)
print('添加成功~,学生信息如下:')
print(students[max(students)])
print('--' * 20)
if choose == 3:
id_number = int(input('请输入已存在的学号:'))
print('学号-{{{}}}-,对应的学生信息如下:\n{}'.format(id_number, students[id_number]))
print('请选择要更改的学生信息:')
print('1.学生姓名')
print('2.学生年龄')
print('3.学生班级')
print('4.学生性别')
number = int(input('请输入需要更改的序号:'))
if number == 1:
name1 = input('请输入学生姓名:')
students[id_number]['name'] = name1
if number == 2:
age1 = int(input('请输入学生年龄:'))
students[id_number]['age'] = age1
if number == 3:
class_number1 = int(input('请输入学生班级:'))
students[id_number]['class_number'] = class_number1
if number == 4:
sex1 = input('请输入学生性别(male/famale):')
students[id_number]['sex'] = sex1
print('更新后的学生信息如下:')
print(students[id_number])
print('--' * 20)
if choose == 4:
id_number = int(input('请输入学号:'))
delete_students(id_number)
print('--' * 20)
if choose == 5:
print('您已退出~')
print('--' * 20)
break
推荐
![](https://res.hc-cdn.com/ecology/9.3.130/v2_resources\images\global\blog-dialog.png)
华为开发者空间发布
让每位开发者拥有一台云主机
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)