• What's wrong with Army Battles

 

my code:

class Warrior:
    def __init__(self):
       self.health = 50
       self.attack = 5
  @property
    def is_alive(self):
       return self.health >= 0

class Knight(Warrior):
    def __init__(self):
        super().__init__()
        self.attack = 7

class Army():
    def __init__(self):        
        self.arr = []
    def add_units(self, unit, number):
        [self.arr.append(unit())for i in range(number)]       
    @property
    def is_alive(self):
        return self.arr[-1].is_alive

class Battle():
    def __init__(self):        
        self.i = 0
        self.j = 0
    def fight(self, army_1, army_2):
        self.army_1 = army_1
        self.army_2 = army_2
        while self.i < len(self.army_1.arr) and self.j < len(self.army_2.arr):
            while self.army_1.arr[self.i].is_alive and self.army_2.arr[self.j].is_alive:
                self.army_2.arr[self.j].health -= self.army_1.arr[self.i].attack
                if self.army_2.arr[self.j].is_alive:
                    self.army_1.arr[self.i].health -= self.army_2.arr[self.j].attack
            if self.army_1.arr[self.i].is_alive: self.j += 1
            else: self.i += 1
        return self.army_1.is_alive

for some reason test:

army_1 = Army()
army_2 = Army()
army_1.add_units(Warrior, 1)
army_2.add_units(Warrior, 2)
battle = Battle()
battle.fight(army_1, army_2)

works in "Run Code" but don't work in 'Check Solution'