CTF入门刷题

文章详细介绍了Python中定义的几个类,如动物、食肉动物、食草动物,以及狮子、马和兔子的具体实现。展示了如何进行捕猎和战斗操作,最后通过实例化和循环演示了它们的行为。
摘要由CSDN通过智能技术生成

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值