分别定义一个教师类teacher和干部类leader
时间: 2023-07-10 13:03:41 浏览: 96
分别声明Teacher(教师)类和Cadre(干部)类,采用多重继承方式由这两个类派生出新类Teacher_Cadre(教师兼干部)。要求:①在两个基类中都包含
教师类Teacher的定义:
```python
class Teacher:
def __init__(self, name, age, gender, subject):
self.name = name
self.age = age
self.gender = gender
self.subject = subject
def teach(self):
print("I am teaching", self.subject)
def introduce(self):
print("My name is", self.name, ", I am", self.age, "years old. I am a", self.gender, "and I teach", self.subject)
```
干部类Leader的定义:
```python
class Leader:
def __init__(self, name, age, gender, position):
self.name = name
self.age = age
self.gender = gender
self.position = position
def manage(self):
print("I am managing", self.position)
def introduce(self):
print("My name is", self.name, ", I am", self.age, "years old. I am a", self.gender, "and I am in charge of", self.position)
```
以上是两个简单的类定义,教师类有属性姓名、年龄、性别和科目,方法包括教学和介绍自己;干部类有属性姓名、年龄、性别和职位,方法包括管理和介绍自己。
阅读全文