# What am i doing wrong? (python) hit and freeze

**URL:** <https://discourse.codecombat.com/t/what-am-i-doing-wrong-python-hit-and-freeze/13558>\
**Category:** Uncategorized\
**Created:** [January 14, 2018, 8:29pm UTC](https://discourse.codecombat.com/t/what-am-i-doing-wrong-python-hit-and-freeze/13558 "2018-01-14T20:29:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![no\_one\_in\_particular](https://avatars.discourse-cdn.com/v4/letter/n/8491ac/32.png) [@no\_one\_in\_particular](https://discourse.codecombat.com/u/no_one_in_particular)\
**Post date:** [January 14, 2018, 8:29pm UTC](https://discourse.codecombat.com/t/what-am-i-doing-wrong-python-hit-and-freeze/13558/1 "2018-01-14T20:29:09Z")

</div>

# 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()  
canAttack = inAttackRange(enemy)  
# 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!  
if canAttack:  
enemy = hero.findNearestEnemy()  
hero.attack(enemy)

---

<div class="post-metadata">

**Author:** ![kinasharma01](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/kinasharma01/32/10862_2.png) [@kinasharma01](https://discourse.codecombat.com/u/kinasharma01)\
**Post date:** [January 14, 2018, 9:22pm UTC](https://discourse.codecombat.com/t/what-am-i-doing-wrong-python-hit-and-freeze/13558/2 "2018-01-14T21:22:22Z")

</div>

Please format your code according to the FAQ. I think that it is you line of code with this:

```python
canAttack = inAttackRange

```

You might not need that line of code.
