# Zoo Keeper Python Help

**URL:** <https://discourse.codecombat.com/t/zoo-keeper-python-help/6422>\
**Category:** Uncategorized\
**Created:** [January 8, 2016, 5:52pm UTC](https://discourse.codecombat.com/t/zoo-keeper-python-help/6422 "2016-01-08T17:52:20Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![lundor5](https://avatars.discourse-cdn.com/v4/letter/l/7993a0/32.png) [@lundor5](https://discourse.codecombat.com/u/lundor5)\
**Post date:** [January 8, 2016, 5:52pm UTC](https://discourse.codecombat.com/t/zoo-keeper-python-help/6422/1 "2016-01-08T17:52:21Z")

</div>

My hero summons the four soldiers and they move to the points but they dont attack and the ogres then kill one and attack the crate and then the yeti is summoned also i want to summon more than four soldiers so that i have more men to defend the crate so how do i do that heres my code

```python
points = []
points[0] = {"x": 33, "y": 42}
points[1] = {"x": 47, "y": 42}
points[2] = {"x": 33, "y": 26}
points[3] = {"x": 47, "y": 26}

while self.gold <=80:
    coin = self.findNearest(self.findItems())
    if coin:
        self.move(coin.pos)
for i in range(4):
    self.summon("soldier")

loop:
    friends = self.findFriends()
    for j in range(len(friends)):
        point = points[j]
        friend = friends[j]
        enemy = friend.findNearestEnemy()
        if enemy and enemy.team == "ogres" and friend.distanceTo(enemy) < 5:
            self.command(friend, "attack", enemy)
                
        if friend:
            self.command(friend, "move", point)
```

---

<div class="post-metadata">

**Author:** ![ChronistGilver](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/chronistgilver/32/3778_2.png) [@ChronistGilver](https://discourse.codecombat.com/u/ChronistGilver)\
**Post date:** [January 9, 2016, 2:34am UTC](https://discourse.codecombat.com/t/zoo-keeper-python-help/6422/2 "2016-01-09T02:34:37Z")

</div>

When you run your code, your code will command your friends to atack an eneny that meets the requirements. However, you then check for a friend. If there is, theb that friend will move to the point, overriding the attack command. Don’t use a separate if-statement; just use an else-block.

---

<div class="post-metadata">

**Author:** ![lundor5](https://avatars.discourse-cdn.com/v4/letter/l/7993a0/32.png) [@lundor5](https://discourse.codecombat.com/u/lundor5)\
**Post date:** [January 10, 2016, 10:17pm UTC](https://discourse.codecombat.com/t/zoo-keeper-python-help/6422/3 "2016-01-10T22:17:12Z")

</div>

thanks i beat it next level

---

<div class="post-metadata">

**Author:** ![Thelightside](https://avatars.discourse-cdn.com/v4/letter/t/b782af/32.png) [@Thelightside](https://discourse.codecombat.com/u/Thelightside)\
**Post date:** [January 17, 2016, 12:47am UTC](https://discourse.codecombat.com/t/zoo-keeper-python-help/6422/4 "2016-01-17T00:47:20Z")

</div>

Can You plz tell me how to do that since I am new.(Python)@lundor5

---

<div class="post-metadata">

**Author:** ![AdrianCgw](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@AdrianCgw](https://discourse.codecombat.com/u/AdrianCgw)\
**Post date:** [January 18, 2016, 1:31am UTC](https://discourse.codecombat.com/t/zoo-keeper-python-help/6422/5 "2016-01-18T01:31:17Z")

</div>

See the other zookeeper thread. It discusses exactly this error:

> [@Zoo Keeper Help!(Python)](https://discourse.codecombat.com/t/zoo-keeper-help-python/6480/4):
>
> The last if if friend: self.command(friend, "move", point) is always true so every attack command will be followed by a “move” command which overwrites the attack command. attack + move = move only

---

<div class="post-metadata">

**Author:** ![lundor5](https://avatars.discourse-cdn.com/v4/letter/l/7993a0/32.png) [@lundor5](https://discourse.codecombat.com/u/lundor5)\
**Post date:** [January 19, 2016, 5:36pm UTC](https://discourse.codecombat.com/t/zoo-keeper-python-help/6422/6 "2016-01-19T17:36:47Z")

</div>

i beat it weeks ago i changed to an else after the if enemy

---

<div class="post-metadata">

**Author:** ![sunshin3crow](https://avatars.discourse-cdn.com/v4/letter/s/7ab992/32.png) [@sunshin3crow](https://discourse.codecombat.com/u/sunshin3crow)\
**Post date:** [June 2, 2021, 8:37pm UTC](https://discourse.codecombat.com/t/zoo-keeper-python-help/6422/7 "2021-06-02T20:37:58Z")

</div>

I NEED HELP it says there an error with that I can’t move to point.pos

# Protect the cage.

# Put a soldier at each X.

points =   
points[0] = {“x”: 33, “y”: 42}  
points[1] = {“x”: 47, “y”: 42}  
points[2] = {“x”: 33, “y”: 26}  
points[3] = {“x”: 47, “y”: 26}

# 1. Collect 80 gold.

while True:  
coin = hero.findNearest(hero.findItems())  
if hero.gold \<=80:  
if coin:  
hero.move(coin.pos)

# 2. Build 4 soldiers.

for i in range(4):  
hero.summon(“soldier”)

# 3. Send your soldiers into position.

while True:  
friends = hero.findFriends()  
for j in range(len(friends)):  
point = points[j]  
friend = friends[j]  
enemy = friend.findNearestEnemy()  
if enemy and enemy.team == “ogres” and friend.distanceTo(enemy) \< 5:  
# Command friend to attack.  
hero.command(friend, “attack”, enemy)  
pass  
else:  
hero.command(friend, “move”, point.pos)  
# Command friend to move to point.  
pass

---

<div class="post-metadata">

**Author:** ![KATIE\_LUK](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/katie_luk/32/24038_2.png) [@KATIE\_LUK](https://discourse.codecombat.com/u/KATIE_LUK)\
**Post date:** [August 25, 2021, 9:15am UTC](https://discourse.codecombat.com/t/zoo-keeper-python-help/6422/8 "2021-08-25T09:15:15Z")

</div>

Hello! I would like to ask do you still need help with passing the level, or you already passed it??

---

<div class="post-metadata">

**Author:** ![sunshin3crow](https://avatars.discourse-cdn.com/v4/letter/s/7ab992/32.png) [@sunshin3crow](https://discourse.codecombat.com/u/sunshin3crow)\
**Post date:** [August 25, 2021, 2:13pm UTC](https://discourse.codecombat.com/t/zoo-keeper-python-help/6422/9 "2021-08-25T14:13:03Z")

</div>

Already passed it thank you, I could use help with Pender’s Trial.

---

<div class="post-metadata">

**Author:** ![enPointe77](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/enpointe77/32/43632_2.png) [@enPointe77](https://discourse.codecombat.com/u/enPointe77)\
**Post date:** [August 25, 2021, 2:43pm UTC](https://discourse.codecombat.com/t/zoo-keeper-python-help/6422/10 "2021-08-25T14:43:12Z")

</div>

Hi and welcome to the forum!  
@sunshin3crow, I’m so sorry we never even posted on here. But I’m glad you fixed it!
