Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Mad Maxer: Redemption

I have tried so many times and even reproduced some of the code found on here. I’m almost at the point of giving up can someone please help me with this code! Any help is appreciated…

#Commented out to stop infinite loop.
# 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.
    friends = hero.findFriends()
    while friendIndex < len(friends):
        friend = friends[friendIndex]
        if friend:
            if friend.health < leastHealth and friend.type != "archer":
                weakestFriend = friend
                leastHealth = friend.health
                friendIndex += 1
                pass
    # Tell the weakest friends to go home first.
        if weakestFriend:
            hero.say('Hey ' + weakestFriend.id + ', go home!')
        pass

HOW IS THIS WRONG!!!

1 Like

Hi @HarryLM and welcome to the forum! :partying_face:

Here try to delete 8 spaces from before this line.

Also, try to delete this.

Andrei

3 Likes

Actually, the friend.type is required, otherwise you’ll target the archers too. The indentation for friendIndex does need to be corrected tho. Also, here:

    # Tell the weakest friends to go home first.
        if weakestFriend:
            hero.say('Hey ' + weakestFriend.id + ', go home!')
        pass

Typically, the preexisting comments are placed (indented) where you need to have the code. Those three lines need to line up with the comment. (You can just delete the ‘pass’ line if you want…it’s just a place holder, so it not required.)

3 Likes

Oh, that’s right. But it was a long time ago when I completed this level, so I did not remember all of it.

Andrei

3 Likes

Guys thank you so much, I fixed the indentation and it worked :sweat_smile:

You guys are the best!

2 Likes