-
why not pass the test
I would like to give some feedback about ... the result is correct, but in the test a different result. I have 60, but it shows that 12
class Warrior: def __init__(self): self.health = 50 self.dam = 5 @property def is_alive(self): if self.health > 0: return True else: return False pass
class Knight(Warrior): def init(self): self.health = 50 self.dam = 7 pass
class Defender(Warrior): def init(self): self.health = 60 self.dam = 3 self.deff=2 pass
class Army(): def init(self): self.solder = [] def add_units(self, unit, numb): solder=[] for i in range(numb): self.solder.append(unit()) return solder pass
class Battle():
def fight(self, arm1, arm2): colarm1=0 colarm2=0 while (colarm1<len(arm1.solder)) and (colarm2<len(arm2.solder)): if hasattr( arm1.solder[colarm1], 'deff'): arm2.solder[colarm2].dam=arm2.solder[colarm2].dam-arm1.solder[colarm1].deff if arm2.solder[colarm2].dam<=0: arm2.solder[colarm2].dam=0 if hasattr(arm2.solder[colarm2], 'deff'): arm1.solder[colarm1].dam=arm1.solder[colarm1].dam-arm2.solder[colarm2].deff if arm1.solder[colarm1].dam<=0: arm1.solder[colarm1].dam=0 while True: arm2.solder[colarm2].health=arm2.solder[colarm2].health-arm1.solder[colarm1].dam if arm2.solder[colarm2].health<=0: if hasattr( arm2.solder[colarm2], 'deff'): arm1.solder[colarm1].dam=arm1.solder[colarm1].dam+arm2.solder[colarm2].deff colarm2+=1 break arm1.solder[colarm1].health=arm1.solder[colarm1].health-arm2.solder[colarm2].dam if arm1.solder[colarm1].health<=0: if hasattr( arm1.solder[colarm1], 'deff'): arm2.solder[colarm2].dam=arm2.solder[colarm2].dam+arm1.solder[colarm1].deff colarm1+=1 break if(colarm1==len(arm1.solder)): return False if(colarm2==len(arm2.solder)): return True return 0 pass def fight(unit_1, unit_2): max=unit_1.health if hasattr(unit_1, 'deff'): unit_2.dam=unit_2.dam-unit_1.deff if unit_2.dam<=0: unit_2.dam=0 if hasattr(unit_2, 'deff'): unit_1.dam=unit_1.dam-unit_2.deff if unit_1.dam<=0: unit_1.dam=0 while max>0: unit_2.health=unit_2.health-unit_1.dam if unit_2.health<=0: return True unit_1.health=unit_1.health-unit_2.dam if unit_1.health<=0: return False if unit_2.health<unit_1.health: max=unit_2.health else: max=unit_1.health return 0
From: https://py.checkio.org/mission/the-defenders/solve/
HTTP_USER_AGENT:
Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36
Created at: 2018/11/07 13:11; Updated at: 2018/11/08 08:33