buuctf:BUUCTF在线评测 (buuoj.cn)
ctfshow:ctf.show
ctfhub:CTFHub
class Animal(object): #动物类 def __init__(self): self.name = name self.weight = weight class Hunter(Animal): #食肉动物类 def hunt(self,obj): if self.weight > obj.weight: self.weight = self.weight + 20 obj.die else: self.weight = self.weight - 5 obj.avoid() def fight(self,obj): if self.weight > obj.weight: return self else: return obj class Prey(Animal): #食草动物类 def avoid(self): print('% s 成功躲避追杀' % (self.name)) class Lion(Hunter): #狮子类 def __init__(self,name,weight): self.name = "狮子" + name self.weight = weight class Horse(Prey): #马类 def __init__(self,name,weight): self.name = "小马" + name self.weight = weight class Rabbit(Prey): #兔子类 def __init__(self,name,weight): self.name = "兔子" + name self.weight = weight andy = horse("andy",100) #定义对象:名字,体重 bunny = rabbit("bunny",30) messy = lion("messy",150) bunny.avoid() messy.hunt(andy) messy = lion("messy",150) horses =[horse("1号",80),horse("2号",170),horse("3号",100),horse("4号",140),horse("5号",120),] for horse in horses: messy.hunt(horse) messy = lion("messy",150) ronaldo =lion("ronaldo",130) horses =[horse("1号",80),horse("2号",170),horse("3号",100),horse("4号",140),horse("5号",120),] for horse in horse: messy.fight(ronaldo) winner = fight(messy,ronaldo) #争夺权 print('% s 即将被杀,是否拯救?' % (horse.name)) ipt = None #接受输入 while ipt !="y" and ipt !="n": #输入错误 print("错误输入") ipt