# Hit and Freeze Python

**URL:** <https://discourse.codecombat.com/t/hit-and-freeze-python/13316>\
**Category:** Level Help\
**Created:** [December 20, 2017, 3:01am UTC](https://discourse.codecombat.com/t/hit-and-freeze-python/13316 "2017-12-20T03:01:58Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![agarionotpro](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/agarionotpro/32/7218_2.png) [@agarionotpro](https://discourse.codecombat.com/u/agarionotpro)\
**Post date:** [December 20, 2017, 3:01am UTC](https://discourse.codecombat.com/t/hit-and-freeze-python/13316/1 "2017-12-20T03:01:58Z")

</div>

I am stuck on the level, “Hit and Freeze.”  
This is my code:

# You are trapped. Don’t move, it’ll be painful.

# This function checks if the enemy is in your attack range.

def inAttackRange(enemy):  
distance = hero.distanceTo(enemy)  
# Almost all swords have attack range of 3.  
if distance \<= 3:  
return True  
else:  
return False

# Attack ogres only when they’re within reach.

while True:  
# Find the nearest enemy and store it in a variable.  
enemy = hero.findNearestEnemy()  
# Call inAttackRange(enemy), with the enemy as the argument  
# and save the result in the variable canAttack.  
canAttack = inAttackRange()  
# If the result stored in canAttack is True, then attack!  
hero.attack(enemy)  
pass

PLEASE HELP:(😱

---

<div class="post-metadata">

**Author:** ![agarionotpro](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/agarionotpro/32/7218_2.png) [@agarionotpro](https://discourse.codecombat.com/u/agarionotpro)\
**Post date:** [December 20, 2017, 3:03am UTC](https://discourse.codecombat.com/t/hit-and-freeze-python/13316/2 "2017-12-20T03:03:51Z")

</div>

NEVER MIND I PASSED IT 🙂

ACTUALLY NOT ☹  
NO I DID  
SERIOUSLY

---

<div class="post-metadata">

**Author:** ![SuperSmacker](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/supersmacker/32/8385_2.png) [@SuperSmacker](https://discourse.codecombat.com/u/SuperSmacker)\
**Post date:** [December 20, 2017, 4:23am UTC](https://discourse.codecombat.com/t/hit-and-freeze-python/13316/3 "2017-12-20T04:23:53Z")

</div>

![HitAndFreezeCheat](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/7/7d0338c53ac31a464093b8f86daa96cb2ca01e2a.jpg)

---

<div class="post-metadata">

**Author:** ![MunkeyShynes](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/munkeyshynes/32/9277_2.png) [@MunkeyShynes](https://discourse.codecombat.com/u/MunkeyShynes)\
**Post date:** [December 20, 2017, 12:43pm UTC](https://discourse.codecombat.com/t/hit-and-freeze-python/13316/4 "2017-12-20T12:43:24Z")

</div>

@agarionotpro

I’m confused. Did you pass the level or not?

---

<div class="post-metadata">

**Author:** ![agarionotpro](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/agarionotpro/32/7218_2.png) [@agarionotpro](https://discourse.codecombat.com/u/agarionotpro)\
**Post date:** [December 21, 2017, 12:06am UTC](https://discourse.codecombat.com/t/hit-and-freeze-python/13316/5 "2017-12-21T00:06:02Z")

</div>

I finished the level

---

<div class="post-metadata">

**Author:** ![Torazo\_TOKUDA](https://avatars.discourse-cdn.com/v4/letter/t/8797f3/32.png) [@Torazo\_TOKUDA](https://discourse.codecombat.com/u/Torazo_TOKUDA)\
**Post date:** [July 17, 2018, 2:50am UTC](https://discourse.codecombat.com/t/hit-and-freeze-python/13316/6 "2018-07-17T02:50:02Z")

</div>

which code did you use?

Mod edit: Please do not request solutions. The purpose of this board is to assist people with their code. Simply providing solutions is counter productive to the learning process. There are many people here willing and able to assist you with your code and help you figure out what the problem is, but we do not just give the answers. Thanks.

---

<div class="post-metadata">

**Author:** ![Chaboi\_3000](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/chaboi_3000/32/48486_2.png) [@Chaboi\_3000](https://discourse.codecombat.com/u/Chaboi_3000)\
**Post date:** [July 17, 2018, 3:26am UTC](https://discourse.codecombat.com/t/hit-and-freeze-python/13316/7 "2018-07-17T03:26:28Z")

</div>

Please do not ask for codes please

---

<div class="post-metadata">

**Author:** ![Torazo\_TOKUDA](https://avatars.discourse-cdn.com/v4/letter/t/8797f3/32.png) [@Torazo\_TOKUDA](https://discourse.codecombat.com/u/Torazo_TOKUDA)\
**Post date:** [July 17, 2018, 5:40am UTC](https://discourse.codecombat.com/t/hit-and-freeze-python/13316/8 "2018-07-17T05:40:04Z")

</div>

I can’t find to finish the level

---

<div class="post-metadata">

**Author:** ![Chaboi\_3000](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/chaboi_3000/32/48486_2.png) [@Chaboi\_3000](https://discourse.codecombat.com/u/Chaboi_3000)\
**Post date:** [July 17, 2018, 6:56am UTC](https://discourse.codecombat.com/t/hit-and-freeze-python/13316/9 "2018-07-17T06:56:24Z")

</div>

Can you post your current code so we can help you?

---

<div class="post-metadata">

**Author:** ![Deadpool198](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/deadpool198/32/16753_2.png) [@Deadpool198](https://discourse.codecombat.com/u/Deadpool198)\
**Post date:** [July 17, 2018, 7:16am UTC](https://discourse.codecombat.com/t/hit-and-freeze-python/13316/10 "2018-07-17T07:16:29Z")

</div>

Wait, @SuperSmacker that’s a solution could you get rid of it. (actually it doesn’t really matter, do what you think)

---

<div class="post-metadata">

**Author:** ![Torazo\_TOKUDA](https://avatars.discourse-cdn.com/v4/letter/t/8797f3/32.png) [@Torazo\_TOKUDA](https://discourse.codecombat.com/u/Torazo_TOKUDA)\
**Post date:** [July 17, 2018, 8:26am UTC](https://discourse.codecombat.com/t/hit-and-freeze-python/13316/11 "2018-07-17T08:26:51Z")

</div>

here is the code

# This function checks if the enemy is in your attack range.

def inAttackRange(enemy):  
distance = hero.distanceTo(enemy)  
# Almost all swords have attack range of 3.  
if distance \<= 3:  
return True  
else:  
return False

# Attack ogres only when they’re within reach.

while True:  
# Find the nearest enemy and store it in a variable.  
enemy = hero.findNearestEnemy()  
# Call inAttackRange(enemy), with the enemy as the argument  
# and save the result in the variable canAttack.  
canAttack = inAttackRange  
# If the result stored in canAttack is True, then attack!  
hero.attack(enemy)  
pass

this code attacks the munchkins and kills 5 exactly but when the others escape the hero follows it and takes too much damage from the trap.

---

<div class="post-metadata">

**Author:** ![Chaboi\_3000](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/chaboi_3000/32/48486_2.png) [@Chaboi\_3000](https://discourse.codecombat.com/u/Chaboi_3000)\
**Post date:** [July 17, 2018, 9:22am UTC](https://discourse.codecombat.com/t/hit-and-freeze-python/13316/12 "2018-07-17T09:22:30Z")

</div>

Can you format your code so we can see clearly? Use the \</\> button to do that.

---

<div class="post-metadata">

**Author:** ![MunkeyShynes](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/munkeyshynes/32/9277_2.png) [@MunkeyShynes](https://discourse.codecombat.com/u/MunkeyShynes)\
**Post date:** [July 17, 2018, 10:57am UTC](https://discourse.codecombat.com/t/hit-and-freeze-python/13316/13 "2018-07-17T10:57:54Z")

</div>

Please learn to post your code properly. It’s really easy and only requires a very small amount of effort.

![FormatCode](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/0/03e091050fe4eed8c0076eee4ab979e171ba14c3.jpg)

To post your code **_from the game_** , use the **\</\>** button or it won’t format properly. When you click the **\</\>** button, the following will appear:

![PostCode](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/7/78430fb6ee8dec450c5a0355db89d0dc189030b4.JPG)

Please paste **ALL** of your code inside the triple back tick marks.

# ``` \<— Triple back tick marks.

**Paste ALL of your code in here.**

# ``` \<— Triple back tick marks.

There are many people here willing and able to help. If you use the **\</\>** button correctly, then **ALL** of your code should look like this:

```python
while True:
    enemy = hero.findNearestEnemy()
    if enemy:
        hero.attack(enemy)
    else:
        hero.say("My code is formatted properly")

```

If **ALL** of your code isn’t formatted like the code above, then you’re doing it wrong and **_we can’t see the structure of the code_** to troubleshoot whether or not that is the issue. Use the **\</\>** button and **_help us help you_**. This works when sending a private message as well.

Thank you.

---

<div class="post-metadata">

**Author:** ![Chaboi\_3000](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/chaboi_3000/32/48486_2.png) [@Chaboi\_3000](https://discourse.codecombat.com/u/Chaboi_3000)\
**Post date:** [July 17, 2018, 10:59am UTC](https://discourse.codecombat.com/t/hit-and-freeze-python/13316/14 "2018-07-17T10:59:59Z")

</div>

But it takes us a long time to write these kind of posts, for just a tiny thing ;( LOL

---

<div class="post-metadata">

**Author:** ![MunkeyShynes](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/munkeyshynes/32/9277_2.png) [@MunkeyShynes](https://discourse.codecombat.com/u/MunkeyShynes)\
**Post date:** [July 17, 2018, 11:00am UTC](https://discourse.codecombat.com/t/hit-and-freeze-python/13316/15 "2018-07-17T11:00:40Z")

</div>

Nope. Copy and paste. I’ve posted that so many times that I have it saved.

---

<div class="post-metadata">

**Author:** ![Chaboi\_3000](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/chaboi_3000/32/48486_2.png) [@Chaboi\_3000](https://discourse.codecombat.com/u/Chaboi_3000)\
**Post date:** [July 17, 2018, 11:01am UTC](https://discourse.codecombat.com/t/hit-and-freeze-python/13316/16 "2018-07-17T11:01:10Z")

</div>

… (20 fainted @Chaboi_3000’s ) Maybe have a notepad of all copy and paste items. Then you can choose a variety of posts that are going to be repeated.

---

<div class="post-metadata">

**Author:** ![MunkeyShynes](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/munkeyshynes/32/9277_2.png) [@MunkeyShynes](https://discourse.codecombat.com/u/MunkeyShynes)\
**Post date:** [July 17, 2018, 11:05am UTC](https://discourse.codecombat.com/t/hit-and-freeze-python/13316/17 "2018-07-17T11:05:32Z")

</div>

Set up canned replies, it’s easier. Just click on the gear and set them up. 🕶

---

<div class="post-metadata">

**Author:** ![Chaboi\_3000](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/chaboi_3000/32/48486_2.png) [@Chaboi\_3000](https://discourse.codecombat.com/u/Chaboi_3000)\
**Post date:** [July 17, 2018, 11:06am UTC](https://discourse.codecombat.com/t/hit-and-freeze-python/13316/18 "2018-07-17T11:06:14Z")

</div>

I’m sad that only admins and mods have them, we only have the default options ;(

---

<div class="post-metadata">

**Author:** ![MunkeyShynes](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/munkeyshynes/32/9277_2.png) [@MunkeyShynes](https://discourse.codecombat.com/u/MunkeyShynes)\
**Post date:** [July 17, 2018, 11:08am UTC](https://discourse.codecombat.com/t/hit-and-freeze-python/13316/19 "2018-07-17T11:08:26Z")

</div>

Oh, didn’t know that the option wasn’t available to you. Someday…

Until then, use a word doc or .txt. Still fast and easy.

---

<div class="post-metadata">

**Author:** ![Chaboi\_3000](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/chaboi_3000/32/48486_2.png) [@Chaboi\_3000](https://discourse.codecombat.com/u/Chaboi_3000)\
**Post date:** [July 17, 2018, 11:11am UTC](https://discourse.codecombat.com/t/hit-and-freeze-python/13316/20 "2018-07-17T11:11:10Z")

</div>

Btw moderation in discord servers are tough when so many people hate each other, I’m like warn then kick then ban, and it’s making me crazy. You’re lucky you’re a mod of a peaceful chat because mines are indescribably out of control.

[Next page](https://discourse.codecombat.com/t/hit-and-freeze-python/13316.md?page=2)
