# Issue with Peasant Protection

**URL:** <https://discourse.codecombat.com/t/issue-with-peasant-protection/9058>\
**Category:** Level Help\
**Created:** [September 25, 2016, 6:04pm UTC](https://discourse.codecombat.com/t/issue-with-peasant-protection/9058 "2016-09-25T18:04:38Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Autri\_Basu](https://avatars.discourse-cdn.com/v4/letter/a/e9a140/32.png) [@Autri\_Basu](https://discourse.codecombat.com/u/Autri_Basu)\
**Post date:** [September 25, 2016, 6:04pm UTC](https://discourse.codecombat.com/t/issue-with-peasant-protection/9058/1 "2016-09-25T18:04:38Z")

</div>

I recently tried to rebeat Peasant Protection, and even after following the instructions I had trouble.  
Here is my code:

```python
while True:
    enemy = hero.findNearestEnemy()
    distance = hero.distanceTo(enemy)
    if distance < 10:
        # Attack if they get too close to the peasant.
        self.attack(enemy)
        
    # Else, stay close to the peasant! Use else.
    else:
        self.moveXY(40, 37)
    

```

as you can see, I did what the instructions said, but no matter what i did my code didn’t seem to work. the hints didn’t help either.

---

<div class="post-metadata">

**Author:** ![Bryukh](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/bryukh/32/19597_2.png) [@Bryukh](https://discourse.codecombat.com/u/Bryukh)\
**Post date:** [September 26, 2016, 1:30pm UTC](https://discourse.codecombat.com/t/issue-with-peasant-protection/9058/2 "2016-09-26T13:30:47Z")

</div>

Do you get some errors? Could you explain "doesn’t work?

---

<div class="post-metadata">

**Author:** ![Harry\_the\_Wanderer](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/harry_the_wanderer/32/5369_2.png) [@Harry\_the\_Wanderer](https://discourse.codecombat.com/u/Harry_the_Wanderer)\
**Post date:** [September 27, 2016, 4:17pm UTC](https://discourse.codecombat.com/t/issue-with-peasant-protection/9058/3 "2016-09-27T16:17:03Z")

</div>

@Autri_Basu what kind of sword are you using? I used your code and won the level using the long sword so I am not sure what is happening on your end. Are you using a warrior class to play?

Make sure you can defeat each munchkin with 1 attack and try resubmitting.

---

<div class="post-metadata">

**Author:** ![Gabriel\_Knight](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/gabriel_knight/32/16933_2.png) [@Gabriel\_Knight](https://discourse.codecombat.com/u/Gabriel_Knight)\
**Post date:** [September 15, 2020, 9:25pm UTC](https://discourse.codecombat.com/t/issue-with-peasant-protection/9058/4 "2020-09-15T21:25:51Z")

</div>

I also used a long sword and these to:

![Screenshot 2020-09-15 at 2.25.01 PM](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/3/3b87761d2b9b70ecc167a50bfb3c825ba8026349.png)

---

<div class="post-metadata">

**Author:** ![Lydia\_Song](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/lydia_song/32/31461_2.png) [@Lydia\_Song](https://discourse.codecombat.com/u/Lydia_Song)\
**Post date:** [September 15, 2020, 9:53pm UTC](https://discourse.codecombat.com/t/issue-with-peasant-protection/9058/5 "2020-09-15T21:53:09Z")

</div>

Are you asking for help? Or are you just saying that you used the Long Sword for this level, because if you are, please do not revive dead topics.  
Lydia

---

<div class="post-metadata">

**Author:** ![Gabriel\_Knight](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/gabriel_knight/32/16933_2.png) [@Gabriel\_Knight](https://discourse.codecombat.com/u/Gabriel_Knight)\
**Post date:** [September 15, 2020, 9:58pm UTC](https://discourse.codecombat.com/t/issue-with-peasant-protection/9058/6 "2020-09-15T21:58:01Z")

</div>

I was asking for help but I gave up and just looked up a walk through for on YouTube so  
not anymore no. 🙂

---

<div class="post-metadata">

**Author:** ![Lydia\_Song](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/lydia_song/32/31461_2.png) [@Lydia\_Song](https://discourse.codecombat.com/u/Lydia_Song)\
**Post date:** [September 15, 2020, 9:59pm UTC](https://discourse.codecombat.com/t/issue-with-peasant-protection/9058/7 "2020-09-15T21:59:10Z")

</div>

Ok  
Lydia  
20 characters

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/a/a9445509d1a758c41b5ddcddc8c8e20a5dedb67f.png) [@system](https://discourse.codecombat.com/u/system)\
**Post date:** [September 19, 2020, 10:14am UTC](https://discourse.codecombat.com/t/issue-with-peasant-protection/9058/8 "2020-09-19T10:14:25Z")

</div>

Closed on September 19, 2020, 10:14am UTC

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.
