# \[SOLVED\]Toil and trouble help python

**URL:** https://discourse.codecombat.com/t/solved-toil-and-trouble-help-python/15052
**Category:** Uncategorized
**Created:** [June 26, 2018, 3:05am UTC](https://discourse.codecombat.com/t/solved-toil-and-trouble-help-python/15052 "2018-06-26T03:05:03Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Gamestack](https://avatars.discourse-cdn.com/v4/letter/g/76d3ee/32.png) [@Gamestack](https://discourse.codecombat.com/u/Gamestack)
#### Post date: [June 26, 2018, 3:05am UTC](https://discourse.codecombat.com/t/solved-toil-and-trouble-help-python/15052/1 "2018-06-26T03:05:03Z")

</div>

```python
# Ogre Witches have some unpleasant surprises ready for you.

# Define a chooseTarget function which takes a friend argument
# Returns a target to attack, depending on the type of friend.
# Soldiers should attack the witches, archers should attack nearest enemy.
def chooseTarget(friend):
    enemies = friend.findEnemies()
    enemy = friend.findNearest(enemies)
    witches = self.findByType("witch", enemies)
    witch = friend.findNearest(witches)
    if friend and friend.type is "soldier" and enemy and witch and witch.health > 0:
            friend.command(friend, "attack", witch)
    if friend and friend.type is "archer" and enemy:
        self.command(friend, "attack", enemy)
loop:
    friends = self.findFriends()
    for friend in friends:
        # Use your chooseTarget function to decide what to attack.
        chooseTarget(friend)

```

---

<div class="post-metadata">

### Author: ![Gamestack](https://avatars.discourse-cdn.com/v4/letter/g/76d3ee/32.png) [@Gamestack](https://discourse.codecombat.com/u/Gamestack)
#### Post date: [June 26, 2018, 3:05am UTC](https://discourse.codecombat.com/t/solved-toil-and-trouble-help-python/15052/2 "2018-06-26T03:05:47Z")

</div>

👀  
👅  
Help please.

---

<div class="post-metadata">

### Author: ![Gamestack](https://avatars.discourse-cdn.com/v4/letter/g/76d3ee/32.png) [@Gamestack](https://discourse.codecombat.com/u/Gamestack)
#### Post date: [June 26, 2018, 3:14am UTC](https://discourse.codecombat.com/t/solved-toil-and-trouble-help-python/15052/3 "2018-06-26T03:14:55Z")

</div>

Never mind 😥😥

---

<div class="post-metadata">

### Author: ![Gamestack](https://avatars.discourse-cdn.com/v4/letter/g/76d3ee/32.png) [@Gamestack](https://discourse.codecombat.com/u/Gamestack)
#### Post date: [June 26, 2018, 3:15am UTC](https://discourse.codecombat.com/t/solved-toil-and-trouble-help-python/15052/4 "2018-06-26T03:15:13Z")

</div>

The biggest mistakes are the smallest.

---

<div class="post-metadata">

### Author: ![Gamestack](https://avatars.discourse-cdn.com/v4/letter/g/76d3ee/32.png) [@Gamestack](https://discourse.codecombat.com/u/Gamestack)
#### Post date: [June 26, 2018, 3:15am UTC](https://discourse.codecombat.com/t/solved-toil-and-trouble-help-python/15052/5 "2018-06-26T03:15:34Z")

</div>

![16%20PM](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/8/8c62a5eac269743b46ea512592d49dabe3ce6774.png)

---

<div class="post-metadata">

### Author: ![Gamestack](https://avatars.discourse-cdn.com/v4/letter/g/76d3ee/32.png) [@Gamestack](https://discourse.codecombat.com/u/Gamestack)
#### Post date: [June 26, 2018, 3:16am UTC](https://discourse.codecombat.com/t/solved-toil-and-trouble-help-python/15052/6 "2018-06-26T03:16:18Z")

</div>

yay I finally did it!!

---

<div class="post-metadata">

### Author: ![Seojin\_Roy\_Lee](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/seojin_roy_lee/32/23539_2.png) [@Seojin\_Roy\_Lee](https://discourse.codecombat.com/u/Seojin_Roy_Lee)
#### Post date: [June 26, 2018, 5:03pm UTC](https://discourse.codecombat.com/t/solved-toil-and-trouble-help-python/15052/7 "2018-06-26T17:03:16Z")

</div>

you asked your friend to command him/herself.
