python设计一个学生系统
时间: 2024-03-26 14:38:51 浏览: 6
好的,我可以为您提供一个简单的学生管理系统的 Python 代码,包含学生信息的录入、修改、删除和查询功能。
```python
students = []
class Student:
def __init__(self, name, age, gender, id):
self.name = name
self.age = age
self.gender = gender
self.id = id
def add_student():
name = input("请输入学生姓名:")
age = input("请输入学生年龄:")
gender = input("请输入学生性别:")
id = input("请输入学生学号:")
student = Student(name, age, gender, id)
students.append(student)
print("学生信息录入成功!")
def modify_student():
id = input("请输入要修改的学生学号:")
for student in students:
if student.id == id:
student.name = input("请输入学生姓名:")
student.age = input("请输入学生年龄:")
student.gender = input("请输入学生性别:")
print("学生信息修改成功!")
break
else:
print("未找到该学生!")
def delete_student():
id = input("请输入要删除的学生学号:")
for student in students:
if student.id == id:
students.remove(student)
print("学生信息删除成功!")
break
else:
print("未找到该学生!")
def query_student():
id = input("请输入要查询的学生学号:")
for student in students:
if student.id == id:
print("学生姓名:", student.name)
print("学生年龄:", student.age)
print("学生性别:", student.gender)
print("学生学号:", student.id)
break
else:
print("未找到该学生!")
while True:
print("1. 录入学生信息")
print("2. 修改学生信息")
print("3. 删除学生信息")
print("4. 查询学生信息")
print("5. 退出系统")
choice = input("请选择操作:")
if choice == "1":
add_student()
elif choice == "2":
modify_student()
elif choice == "3":
delete_student()
elif choice == "4":
query_student()
elif choice == "5":
break
else:
print("输入有误,请重新选择!")
```
这是一个比较简单的学生管理系统,您可以基于此进行二次开发,增加更多的功能。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)