用pytho写一个大学生选课系统
时间: 2024-01-05 07:03:04 浏览: 80
好的,一个基本的大学生选课系统需要包含以下功能:
1. 学生账号管理:包括学生注册、登录、修改密码等功能。
2. 课程管理:包括课程信息查询、选课、退课等功能。
3. 学生信息管理:包括学生个人信息修改、查询等功能。
以下是一个简单的Python代码示例,实现基本的大学生选课系统:
```python
# 定义学生类
class Student:
def __init__(self, id, name, password):
self.id = id
self.name = name
self.password = password
self.courses = [] # 学生已选课程列表
def select_course(self, course):
self.courses.append(course)
def withdraw_course(self, course):
self.courses.remove(course)
def display_info(self):
print(f"学生ID: {self.id}\n姓名: {self.name}\n已选课程: {self.courses}")
# 定义课程类
class Course:
def __init__(self, id, name, teacher):
self.id = id
self.name = name
self.teacher = teacher
def display_info(self):
print(f"课程ID: {self.id}\n课程名称: {self.name}\n授课教师: {self.teacher.name}")
# 定义教师类
class Teacher:
def __init__(self, id, name):
self.id = id
self.name = name
# 定义学生管理系统类
class StudentManagementSystem:
def __init__(self):
self.students = [] # 学生列表
self.courses = [] # 课程列表
self.teachers = [] # 教师列表
def register_student(self):
student_id = input("请输入学生ID: ")
student_name = input("请输入学生姓名: ")
student_password = input("请输入密码: ")
self.students.append(Student(student_id, student_name, student_password))
print("注册成功!")
def login_student(self):
student_id = input("请输入学生ID: ")
student_password = input("请输入密码: ")
for student in self.students:
if student.id == student_id and student.password == student_password:
print(f"{student.name},欢迎登录!")
return student
print("账号或密码错误!")
return None
def modify_student_password(self, student):
new_password = input("请输入新密码: ")
student.password = new_password
print("密码修改成功!")
def query_course_info(self):
for course in self.courses:
course.display_info()
def select_course(self, student):
self.query_course_info()
course_id = input("请输入要选的课程ID: ")
for course in self.courses:
if course.id == course_id:
student.select_course(course)
print("选课成功!")
return
print("该课程不存在!")
def withdraw_course(self, student):
student.display_info()
course_id = input("请输入要退的课程ID: ")
for course in student.courses:
if course.id == course_id:
student.withdraw_course(course)
print("退课成功!")
return
print("该课程不存在!")
def modify_student_info(self, student):
new_name = input("请输入新姓名: ")
student.name = new_name
print("个人信息修改成功!")
def run(self):
while True:
print("请选择操作:")
print("1. 学生注册")
print("2. 学生登录")
print("3. 修改密码")
print("4. 查询课程信息")
print("5. 选课")
print("6. 退课")
print("7. 修改个人信息")
print("0. 退出系统")
choice = input()
if choice == "1":
self.register_student()
elif choice == "2":
student = self.login_student()
if student:
while True:
print("请选择操作:")
print("1. 修改密码")
print("2. 查询课程信息")
print("3. 选课")
print("4. 退课")
print("5. 修改个人信息")
print("0. 退出登录")
choice = input()
if choice == "1":
self.modify_student_password(student)
elif choice == "2":
self.query_course_info()
elif choice == "3":
self.select_course(student)
elif choice == "4":
self.withdraw_course(student)
elif choice == "5":
self.modify_student_info(student)
elif choice == "0":
break
elif choice == "3":
student = self.login_student()
if student:
self.modify_student_password(student)
elif choice == "4":
self.query_course_info()
elif choice == "5":
student = self.login_student()
if student:
self.select_course(student)
elif choice == "6":
student = self.login_student()
if student:
self.withdraw_course(student)
elif choice == "7":
student = self.login_student()
if student:
self.modify_student_info(student)
elif choice == "0":
print("谢谢使用!")
break
else:
print("输入有误,请重新输入!")
# 初始化学生管理系统
sms = StudentManagementSystem()
# 添加课程和教师
math_teacher = Teacher("T001", "张三")
english_teacher = Teacher("T002", "李四")
sms.teachers = [math_teacher, english_teacher]
math_course = Course("C001", "高等数学", math_teacher)
english_course = Course("C002", "大学英语", english_teacher)
sms.courses = [math_course, english_course]
# 运行学生管理系统
sms.run()
```
以上代码只是一个简单的示例,实际的大学生选课系统需要更完善的功能和更复杂的实现。
阅读全文