How can I beat mad maxer redemption?

I subscribed and I recently got pender but I can not beat mad maxer this is my code in python can someone fix it?

# You can't reach your friends to defend them!
# Tell them to go home where the archer can help.

while True:
    weakestFriend = None
    leastHealth = 9999
    friendIndex = 0
    # Find which friend has the lowest health.
    while friendIndex<len(weakestFriend):
        
        weakestFriend=friends[leastHealth]
        if weakestFriend:
            hero.say('Hey ' + weakestFriend.id + ', go home!')
            friendIndex+=1


1 Like

“brittle morale” level for pretty much the same

1 Like

Well, you’re using leastHealth for index, instead of friendIndex …

You’re supposed to go through the list of friends (something like friend = friends[index]) and update the weakestFriend and leastHealth variables when you find a friend that has less health than the current weakest friend. When you went through all of them, you have the weakest friend stored in weakestFriend

1 Like

thanks I completed the level

1 Like

Hi All,

I’m stuck on this level as well. I think I have the read of the array and the assignment of weakestFriend running correctly, but when the hero calls the friends’ names, they don’t run. Anyone else running into this? Have any ideas?

Here’s what I’m using:

while True:
weakestFriend = None
leastHealth = 9999
friendIndex = 0
# Find which friend has the lowest health.
friends = hero.findFriends()

while friendIndex < len(friends):
    friend = friends[friendIndex]
    if friend.health < leastHealth:
        weakestFriend = friend
        leastHealth = friend.health
    friendIndex += 1
# Tell the weakest friends to go home first.
if weakestFriend:
    hero.say('Hey ' + weakestFriend.id + ', go home!')

Figured it out. Needed to add minimum health qualification to line 15 to exclude the archers, who didn’t need to be told to retreat:

15 if friend.health < leastHealth and friend.health > 30:

probably would have also worked to exclude them by name, e.g.

15 if friend.health < leastHealth and friend.type != “archer”:

It was easy I just used the peasant’s names and told them to go home.