Student类: 属性:身份证号码、姓名、性别、年龄、籍贯、住址,学号; 方法:eat,sleep,print,study; Teacher类: 属性:身份证号码、姓名、性别、年龄、籍贯、住址,职称title; 方法:eat,sleep,print,teach;
时间: 2023-12-22 16:23:42 浏览: 117
class Student:
def __init__(self, id_num, name, gender, age, hometown, address, student_id):
self.id_num = id_num
self.name = name
self.gender = gender
self.age = age
self.hometown = hometown
self.address = address
self.student_id = student_id
def eat(self):
print("I am eating.")
def sleep(self):
print("I am sleeping.")
def print_info(self):
print("ID number:", self.id_num)
print("Name:", self.name)
print("Gender:", self.gender)
print("Age:", self.age)
print("Hometown:", self.hometown)
print("Address:", self.address)
print("Student ID:", self.student_id)
def study(self):
print("I am studying.")
class Teacher:
def __init__(self, id_num, name, gender, age, hometown, address, title):
self.id_num = id_num
self.name = name
self.gender = gender
self.age = age
self.hometown = hometown
self.address = address
self.title = title
def eat(self):
print("I am eating.")
def sleep(self):
print("I am sleeping.")
def print_info(self):
print("ID number:", self.id_num)
print("Name:", self.name)
print("Gender:", self.gender)
print("Age:", self.age)
print("Hometown:", self.hometown)
print("Address:", self.address)
print("Title:", self.title)
def teach(self):
print("I am teaching.")
阅读全文