class Dog: role = 'Dog' def __init__(self,name,breed,attack_val): self.name = name self.breed = breed self.attack_val = attack_val self.life_val = 100 def bite(self,person): person.life_val -= self.attack_val print('狗%s咬人%s 人掉了%s血,还剩%s血'%(self.name,person.name,self.attack_val,person.life_val))class Person: role = 'Person' def __init__(self,name,sex,attack_val): self.name = name self.sex = sex self.life_val = 100 self.attack_val = attack_val def attack(self,dog): dog.life_val -= self.attack_val print('人%s打打狗%s 狗掉了%s血,还剩%s血'%(self.name,dog.name,self.attack_val,dog.life_val))d1 = Dog('叶薇琦','二哈',30)p1 = Person('苏灿吉','男',50)d1.bite(p1)p1.attack(d1)