# \[SOLVED\]Mad Maxer: Redemption

**URL:** <https://discourse.codecombat.com/t/solved-mad-maxer-redemption/22627>\
**Category:** Level Help\
**Created:** [June 29, 2020, 3:18pm UTC](https://discourse.codecombat.com/t/solved-mad-maxer-redemption/22627 "2020-06-29T15:18:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![HarryLM](https://avatars.discourse-cdn.com/v4/letter/h/87869e/32.png) [@HarryLM](https://discourse.codecombat.com/u/HarryLM)\
**Post date:** [June 29, 2020, 3:18pm UTC](https://discourse.codecombat.com/t/solved-mad-maxer-redemption/22627/1 "2020-06-29T15:18:59Z")

</div>

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…

```python
#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!!!

---

<div class="post-metadata">

**Author:** ![AnSeDra](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ansedra/32/13123_2.png) [@AnSeDra](https://discourse.codecombat.com/u/AnSeDra)\
**Post date:** [June 29, 2020, 6:19pm UTC](https://discourse.codecombat.com/t/solved-mad-maxer-redemption/22627/2 "2020-06-29T18:19:43Z")

</div>

Hi @HarryLM and welcome to the forum! 🥳

> [@HarryLM](#):
>
> `friendIndex += 1`

Here try to delete 8 spaces from before this line.

> [@HarryLM](#):
>
> ` and friend.type != "archer"`

Also, try to delete this.

Andrei

---

<div class="post-metadata">

**Author:** ![dedreous](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dedreous/32/13849_2.png) [@dedreous](https://discourse.codecombat.com/u/dedreous)\
**Post date:** [June 29, 2020, 6:25pm UTC](https://discourse.codecombat.com/t/solved-mad-maxer-redemption/22627/3 "2020-06-29T18:25:53Z")

</div>

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:

```python
    # 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.)

---

<div class="post-metadata">

**Author:** ![AnSeDra](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ansedra/32/13123_2.png) [@AnSeDra](https://discourse.codecombat.com/u/AnSeDra)\
**Post date:** [June 29, 2020, 6:48pm UTC](https://discourse.codecombat.com/t/solved-mad-maxer-redemption/22627/4 "2020-06-29T18:48:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![HarryLM](https://avatars.discourse-cdn.com/v4/letter/h/87869e/32.png) [@HarryLM](https://discourse.codecombat.com/u/HarryLM)\
**Post date:** [June 30, 2020, 8:23am UTC](https://discourse.codecombat.com/t/solved-mad-maxer-redemption/22627/5 "2020-06-30T08:23:07Z")

</div>

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

You guys are the best!

---

<div class="post-metadata">

**Author:** ![Cedar](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/cedar/32/29302_2.png) [@Cedar](https://discourse.codecombat.com/u/Cedar)\
**Post date:** [June 5, 2022, 4:55pm UTC](https://discourse.codecombat.com/t/solved-mad-maxer-redemption/22627/6 "2022-06-05T16:55:45Z")

</div>

Can anyone help me?  
My code:

```python
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

```

---

<div class="post-metadata">

**Author:** ![Aya](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/aya/32/42680_2.png) [@Aya](https://discourse.codecombat.com/u/Aya)\
**Post date:** [June 5, 2022, 5:47pm UTC](https://discourse.codecombat.com/t/solved-mad-maxer-redemption/22627/7 "2022-06-05T17:47:53Z")

</div>

> [@Cedar](#):
>
> ```python
> if weakestFriend:
> hero.say('Hey ' + weakestFriend.id + ', go home!')
> pass
> 
> ```

Those should be outside the while loop but inside the while-true loop
