# Hunting Party - stuck! (Python)

**URL:** <https://discourse.codecombat.com/t/hunting-party-stuck-python/13251>\
**Category:** Level Help\
**Created:** [December 14, 2017, 2:25am UTC](https://discourse.codecombat.com/t/hunting-party-stuck-python/13251 "2017-12-14T02:25:56Z")\
**Posts on this page:** 10\
**Page:** 2

<div class="post-metadata">

**Author:** ![Manuel\_Morales](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/manuel_morales/32/16584_2.png) [@Manuel\_Morales](https://discourse.codecombat.com/u/Manuel_Morales)\
**Post date:** [November 26, 2020, 3:49pm UTC](https://discourse.codecombat.com/t/hunting-party-stuck-python/13251/21 "2020-11-26T15:49:00Z")

</div>

```python
# You can use findNearestEnemy() on your soldiers to get their nearest enemy instead of yours.
while True:
    friends = hero.findFriends()
    enemy = hero.findNearestEnemy()
    x = friends.pos.x
    # Use for-loop and for each friend:
    for friend in friends:
        # If they see an enemy then command to attack.
        if enemy:
            hero.command(friend, "attack", enemy)
        # Command to move east by small steps.
        hero.command(friend, "move", {'x': friend.pos.x + 1, 'y': friend pos.y})

```

---

<div class="post-metadata">

**Author:** ![Manuel\_Morales](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/manuel_morales/32/16584_2.png) [@Manuel\_Morales](https://discourse.codecombat.com/u/Manuel_Morales)\
**Post date:** [November 26, 2020, 3:49pm UTC](https://discourse.codecombat.com/t/hunting-party-stuck-python/13251/22 "2020-11-26T15:49:31Z")

</div>

i need help with my code

---

<div class="post-metadata">

**Author:** ![jka2706](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/jka2706/32/13636_2.png) [@jka2706](https://discourse.codecombat.com/u/jka2706)\
**Post date:** [November 26, 2020, 6:01pm UTC](https://discourse.codecombat.com/t/hunting-party-stuck-python/13251/23 "2020-11-26T18:01:14Z")

</div>

Hi Manuel\_Morales,

Two things:

Firstly, read this again:

> [@Manuel\_Morales](#):
>
> ```python
> for friend in friends:
> # If they see an enemy 
> 
> ```

At the moment you’ve set your enemy variable to what the _hero_ sees.

Secondly, I had more success when I put an ‘else’ before the hero.command statement. I also needed to play about with the length of the step each time.

Cheers,

Jenny

---

<div class="post-metadata">

**Author:** ![Manuel\_Morales](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/manuel_morales/32/16584_2.png) [@Manuel\_Morales](https://discourse.codecombat.com/u/Manuel_Morales)\
**Post date:** [November 27, 2020, 2:33pm UTC](https://discourse.codecombat.com/t/hunting-party-stuck-python/13251/24 "2020-11-27T14:33:24Z")

</div>

it says that the parenthesis must match o line 13

---

<div class="post-metadata">

**Author:** ![jka2706](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/jka2706/32/13636_2.png) [@jka2706](https://discourse.codecombat.com/u/jka2706)\
**Post date:** [November 27, 2020, 2:48pm UTC](https://discourse.codecombat.com/t/hunting-party-stuck-python/13251/25 "2020-11-27T14:48:28Z")

</div>

I don’t know which your line 13 is (depends on how many comments you’ve put in). But check all your (, ), { and } to make sure they’ve all got a partner! Or post a screenshot of your code if you can’t work it out.

Jenny

---

<div class="post-metadata">

**Author:** ![Manuel\_Morales](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/manuel_morales/32/16584_2.png) [@Manuel\_Morales](https://discourse.codecombat.com/u/Manuel_Morales)\
**Post date:** [November 27, 2020, 2:50pm UTC](https://discourse.codecombat.com/t/hunting-party-stuck-python/13251/26 "2020-11-27T14:50:21Z")

</div>

![2020-11-27 (2)](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/1/4/147e1c608bab2fd086ad1e727979e3c10c5d80fb.jpeg)

---

<div class="post-metadata">

**Author:** ![Manuel\_Morales](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/manuel_morales/32/16584_2.png) [@Manuel\_Morales](https://discourse.codecombat.com/u/Manuel_Morales)\
**Post date:** [November 27, 2020, 2:53pm UTC](https://discourse.codecombat.com/t/hunting-party-stuck-python/13251/27 "2020-11-27T14:53:40Z")

</div>

```python
# You can use findNearestEnemy() on your soldiers to get their nearest enemy instead of yours.
while True:
    friends = hero.findFriends()
    enemy = hero.findNearestEnemy()
    # Use for-loop and for each friend:
    for friend in friends:
        # If they see an enemy then command to attack.
        if enemy:
            hero.command(friend, "attack", enemy)
        # Command to move east by small steps.
        else:
            hero.command(friend, "move", {'x': friend.pos.x + 1, 'y': friend.pos,y})

```

---

<div class="post-metadata">

**Author:** ![Eric\_Tang](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/eric_tang/32/15310_2.png) [@Eric\_Tang](https://discourse.codecombat.com/u/Eric_Tang)\
**Post date:** [November 27, 2020, 3:06pm UTC](https://discourse.codecombat.com/t/hunting-party-stuck-python/13251/28 "2020-11-27T15:06:42Z")

</div>

> [@Manuel\_Morales](#):
>
> `friend.pos,y`

you put a comma after the friend.pos  
it should be

```python
friend.pos.y

```

---

<div class="post-metadata">

**Author:** ![jka2706](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/jka2706/32/13636_2.png) [@jka2706](https://discourse.codecombat.com/u/jka2706)\
**Post date:** [November 27, 2020, 4:16pm UTC](https://discourse.codecombat.com/t/hunting-party-stuck-python/13251/29 "2020-11-27T16:16:00Z")

</div>

What @Eric_Tang says should sort out the error code.

For this line here:

> [@Manuel\_Morales](#):
>
> ` enemy = hero.findNearestEnemy()`

you need to change to enemy = friend.findNearestEnemy(), and you need to have the line inside the for loop, so that each friend is instructed to find their enemy.

Jenny

---

<div class="post-metadata">

**Author:** ![Manuel\_Morales](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/manuel_morales/32/16584_2.png) [@Manuel\_Morales](https://discourse.codecombat.com/u/Manuel_Morales)\
**Post date:** [November 28, 2020, 2:58pm UTC](https://discourse.codecombat.com/t/hunting-party-stuck-python/13251/30 "2020-11-28T14:58:51Z")

</div>

thanks a lot i got it!!

[Previous page](https://discourse.codecombat.com/t/hunting-party-stuck-python/13251.md?page=1)
