# \[SOLVED\] Python Blind Distance

**URL:** <https://discourse.codecombat.com/t/solved-python-blind-distance/11338>\
**Category:** Level Help\
**Created:** [May 4, 2017, 3:34pm UTC](https://discourse.codecombat.com/t/solved-python-blind-distance/11338 "2017-05-04T15:34:28Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Innerdesert4346](https://avatars.discourse-cdn.com/v4/letter/i/a3d4f5/32.png) [@Innerdesert4346](https://discourse.codecombat.com/u/Innerdesert4346)\
**Post date:** [May 4, 2017, 3:34pm UTC](https://discourse.codecombat.com/t/solved-python-blind-distance/11338/1 "2017-05-04T15:34:28Z")

</div>

I’m trying to complete blind distance but i always run out of time because the wizard gets too tired too fast because he needlessly attacks when he doesn’t need too so i fail i have tried using stuff that isn’t involved in the level but no matter what it fails over and over its frustrating.

---

<div class="post-metadata">

**Author:** ![Hellenar](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/hellenar/32/9100_2.png) [@Hellenar](https://discourse.codecombat.com/u/Hellenar)\
**Post date:** [May 4, 2017, 3:37pm UTC](https://discourse.codecombat.com/t/solved-python-blind-distance/11338/2 "2017-05-04T15:37:44Z")

</div>

Can you please post your code? 🙂

---

<div class="post-metadata">

**Author:** ![Innerdesert4346](https://avatars.discourse-cdn.com/v4/letter/i/a3d4f5/32.png) [@Innerdesert4346](https://discourse.codecombat.com/u/Innerdesert4346)\
**Post date:** [May 4, 2017, 3:46pm UTC](https://discourse.codecombat.com/t/solved-python-blind-distance/11338/3 "2017-05-04T15:46:21Z")

</div>

Mod edit: [Please do not post working code]

---

<div class="post-metadata">

**Author:** ![\_TD\_RodYT](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/_td_rodyt/32/6285_2.png) [@\_TD\_RodYT](https://discourse.codecombat.com/u/_TD_RodYT)\
**Post date:** [May 4, 2017, 5:57pm UTC](https://discourse.codecombat.com/t/solved-python-blind-distance/11338/4 "2017-05-04T17:57:28Z")

</div>

Why would you command your hero to `say("10")`? Surely you defined the variable enemyDistance for a reason. Maybe for you need to say enemyDistance (hint 😉)

---

<div class="post-metadata">

**Author:** ![Innerdesert4346](https://avatars.discourse-cdn.com/v4/letter/i/a3d4f5/32.png) [@Innerdesert4346](https://discourse.codecombat.com/u/Innerdesert4346)\
**Post date:** [May 4, 2017, 10:51pm UTC](https://discourse.codecombat.com/t/solved-python-blind-distance/11338/5 "2017-05-04T22:51:16Z")

</div>

And of course now it works -\_-

---

<div class="post-metadata">

**Author:** ![\_TD\_RodYT](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/_td_rodyt/32/6285_2.png) [@\_TD\_RodYT](https://discourse.codecombat.com/u/_TD_RodYT)\
**Post date:** [May 4, 2017, 11:02pm UTC](https://discourse.codecombat.com/t/solved-python-blind-distance/11338/6 "2017-05-04T23:02:03Z")

</div>

What did you change to make it work?

---

<div class="post-metadata">

**Author:** ![Tailin.Chen](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/tailin.chen/32/7157_2.png) [@Tailin.Chen](https://discourse.codecombat.com/u/Tailin.Chen)\
**Post date:** [December 2, 2017, 8:27am UTC](https://discourse.codecombat.com/t/solved-python-blind-distance/11338/7 "2017-12-02T08:27:40Z")

</div>

thx very much i solved it  
been a great help  
hope i enquire for more problems

---

<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 19, 2017, 12:37am UTC](https://discourse.codecombat.com/t/solved-python-blind-distance/11338/8 "2017-12-19T00:37:52Z")

</div>

I want to know as well.  
I am stuck on this level:yum:

---

<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:17am UTC](https://discourse.codecombat.com/t/solved-python-blind-distance/11338/9 "2018-07-17T02:17:42Z")

</div>

The 10 does not work for me why?

---

<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, 6:28am UTC](https://discourse.codecombat.com/t/solved-python-blind-distance/11338/10 "2018-07-17T06:28:46Z")

</div>

If you want help with your code, please could you post it on the discourse (formatted as it states in the FAQ) and say what you’re having trouble with. Thanks 😉 (also I don’t think @innerdesert4346 is active any more)

---

<div class="post-metadata">

**Author:** ![BrickSageplayz\_Roblo](https://avatars.discourse-cdn.com/v4/letter/b/3bc359/32.png) [@BrickSageplayz\_Roblo](https://discourse.codecombat.com/u/BrickSageplayz_Roblo)\
**Post date:** [November 30, 2018, 7:26pm UTC](https://discourse.codecombat.com/t/solved-python-blind-distance/11338/11 "2018-11-30T19:26:55Z")

</div>

Thanks it worked and it is really helpfull

---

<div class="post-metadata">

**Author:** ![Franz](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/franz/32/9804_2.png) [@Franz](https://discourse.codecombat.com/u/Franz)\
**Post date:** [March 6, 2019, 6:49pm UTC](https://discourse.codecombat.com/t/solved-python-blind-distance/11338/12 "2019-03-06T18:49:16Z")

</div>

Hello I don’t mean to revive this topic , but I didn’t want to create a new topic since it already existed. At first I had code errors but I fixed everything and I don’t have the little duck alerting me.  
The problem now is that my code has no errors and it “runs”, I say it “runs” because my character doesn’t do anything. I don’t know if it is a mistake I made or it’s a bug.  
Please help! my code is below.

```python
def nearestEnemyDistance():
    enemy = hero.findNearestEnemy()
    result = 0
    if enemy:
        result = hero.distanceTo(enemy)
    return result

while True:
    # Call nearestEnemyDistance() and
    # save the result in the variable enemyDistance.
    enemyDistance = nearestEnemyDistance()
    # If the enemyDistance is greater than 0: 
    if hero.distanceTo > 0 : 
        # Say the value of enemyDistance variable.
        hero.say("nearestEnemyDistance()")

```

---

<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:** [March 6, 2019, 7:17pm UTC](https://discourse.codecombat.com/t/solved-python-blind-distance/11338/13 "2019-03-06T19:17:04Z")

</div>

In your `while True` loop, you’ve created a variable that you don’t use - `enemyDistance`. Your `if` statement should include this variable instead of the incomplete method that you currently have and this variable should be the argument in the `hero.say` method.

---

<div class="post-metadata">

**Author:** ![Franz](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/franz/32/9804_2.png) [@Franz](https://discourse.codecombat.com/u/Franz)\
**Post date:** [March 6, 2019, 8:59pm UTC](https://discourse.codecombat.com/t/solved-python-blind-distance/11338/14 "2019-03-06T20:59:55Z")

</div>

so I should use `enemyDistance` in my of statement?

---

<div class="post-metadata">

**Author:** ![Franz](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/franz/32/9804_2.png) [@Franz](https://discourse.codecombat.com/u/Franz)\
**Post date:** [March 6, 2019, 9:01pm UTC](https://discourse.codecombat.com/t/solved-python-blind-distance/11338/15 "2019-03-06T21:01:14Z")

</div>

@MunkeyShynes I guess not it gives the same result

---

<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:** [March 6, 2019, 9:21pm UTC](https://discourse.codecombat.com/t/solved-python-blind-distance/11338/16 "2019-03-06T21:21:02Z")

</div>

Those two changes should have worked. Did you do both of the suggested changes? Please post your code again.

---

<div class="post-metadata">

**Author:** ![xython](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/xython/32/7269_2.png) [@xython](https://discourse.codecombat.com/u/xython)\
**Post date:** [March 6, 2019, 9:24pm UTC](https://discourse.codecombat.com/t/solved-python-blind-distance/11338/17 "2019-03-06T21:24:02Z")

</div>

Because your hero is saying “nearestEnemyDistance()” or “enemyDistance”. These are the names of the function or of the variable and are strings, not actual value. These two hold the value of the distance.  
a = 5  
hero.say ( ‘a’) # output -\> a  
hero.say ( a ) # output -\> 5

[\_TD\_RodYT](https://discourse.codecombat.com/u/_TD_RodYT) [May '17](https://discourse.codecombat.com/t/python-blind-distance/11338/4)  
Why would you command your hero to `say("10")` ? Surely you defined the variable enemyDistance for a reason. Maybe for you need to say enemyDistance

```python
    enemyDistance = nearestEnemyDistance()
    # If the enemyDistance is greater than 0:  
    if hero.distanceTo > 0 : # see above: this line is wrong

```

---

<div class="post-metadata">

**Author:** ![Franz](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/franz/32/9804_2.png) [@Franz](https://discourse.codecombat.com/u/Franz)\
**Post date:** [March 6, 2019, 10:16pm UTC](https://discourse.codecombat.com/t/solved-python-blind-distance/11338/18 "2019-03-06T22:16:07Z")

</div>

```python
def nearestEnemyDistance():
    enemy = hero.findNearestEnemy()
    result = 0
    if enemy:
        result = hero.distanceTo(enemy)
    return result

while True:
    # Call nearestEnemyDistance() and
    # save the result in the variable enemyDistance.
    enemyDistance = nearestEnemyDistance()
    # If the enemyDistance is greater than 0: 
    if hero.distanceTo > 0 : 
        enemyDistance
        # Say the value of enemyDistance variable.
        hero.say("nearestEnemyDistance()")

```

first solution you suggested @MunkeyShynes

---

<div class="post-metadata">

**Author:** ![Franz](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/franz/32/9804_2.png) [@Franz](https://discourse.codecombat.com/u/Franz)\
**Post date:** [March 6, 2019, 10:18pm UTC](https://discourse.codecombat.com/t/solved-python-blind-distance/11338/19 "2019-03-06T22:18:09Z")

</div>

```python
def nearestEnemyDistance():
    enemy = hero.findNearestEnemy()
    result = 0
    if enemy:
        result = hero.distanceTo(enemy)
    return result

while True:
    # Call nearestEnemyDistance() and
    # save the result in the variable enemyDistance.
    enemyDistance = nearestEnemyDistance()
    # If the enemyDistance is greater than 0: 
    if hero.distanceTo > 0 : 
        enemyDistance = nearestEnemyDistance()
        # Say the value of enemyDistance variable.
        hero.say("nearestEnemyDistance()")

```

second one.  
maybe it doesn’t work because I misunderstood your explanation?

---

<div class="post-metadata">

**Author:** ![Franz](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/franz/32/9804_2.png) [@Franz](https://discourse.codecombat.com/u/Franz)\
**Post date:** [March 6, 2019, 10:19pm UTC](https://discourse.codecombat.com/t/solved-python-blind-distance/11338/20 "2019-03-06T22:19:59Z")

</div>

what? I don’t understand

[Next page](https://discourse.codecombat.com/t/solved-python-blind-distance/11338.md?page=2)
