实验内容: 设计一个简单的学生信息管理系统,学生信息包括学号、姓名、年龄、性别、专业、学院等。要求实现以下功能: (1)学生信息录入功能; (2)学生信息浏览功能; (3)学生信息查询功能,按学号、姓名查询; (4)学生信息的删除与修改。Pythen
时间: 2024-12-10 12:55:51 浏览: 30
为了设计一个简单的学生信息管理系统,你可以使用Python的内置数据结构如字典或者列表,配合类(class)来表示每个学生的信息。以下是基本的设计框架:
```python
# 定义一个学生类
class Student:
def __init__(self, id, name, age, gender, major, college):
self.id = id
self.name = name
self.age = age
self.gender = gender
self.major = major
self.college = college
# 创建一个空的学生列表用于存储学生信息
students = []
# 功能函数
def add_student(student_info):
students.append(Student(*student_info))
def view_students():
for student in students:
print(f"ID: {student.id}, Name: {student.name}, Age: {student.age}, Gender: {student.gender}, Major: {student.major}, College: {student.college}")
def search_student(query_type, query_value):
if query_type == "id":
return [student for student in students if student.id == query_value]
elif query_type == "name":
return [student for student in students if student.name == query_value]
else:
print("Invalid query type.")
def delete_student(id):
students = [student for student in students if student.id != id]
def modify_student(id, updated_info):
for student in students:
if student.id == id:
# 更新对应属性
for key, value in updated_info.items():
setattr(student, key, value)
break
# 使用示例
add_student(["001", "张三", 20, "男", "计算机科学", "计算机学院"])
view_students()
search_student("id", "001")
delete_student("001")
```
阅读全文