python学生选课系统代码
时间: 2023-11-14 12:08:00 浏览: 254
python选课系统
以下是一个简单的Python学生选课系统代码,其中包括列举所有课程、选择课程、学生上课和获取课程返回等功能:
```python
class Course:
def __init__(self, name, price):
self.name = name
self.price = price
def work(self):
return "上课中..."
class Student:
def __init__(self, username, password, gender, age):
self.username = username
self.password = password
self.gender = gender
self.age = age
self.courses = []
self.classes = {}
def show_courses(self):
print("所有课程:")
for course in self.courses:
print(course.name)
def select_course(self, course):
self.courses.append(course)
self.classes[course] = []
def attend_class(self, course):
self.classes[course].append("上课中...")
print("上课中...")
def get_course_return(self, course):
ret = course.work()
print("获取课程的返回:", ret)
self.asset += course.price
course1 = Course("语文", 100)
course2 = Course("数学", 120)
course3 = Course("英语", 150)
student1 = Student("Tom", "123456", "男", 18)
student1.select_course(course1)
student1.select_course(course2)
student1.show_courses()
student1.attend_class(course1)
student1.get_course_return(course1)
```
阅读全文