# How to pass Blind Distance

**URL:** <https://discourse.codecombat.com/t/how-to-pass-blind-distance/13290>\
**Category:** Level Help\
**Created:** [December 16, 2017, 7:26pm UTC](https://discourse.codecombat.com/t/how-to-pass-blind-distance/13290 "2017-12-16T19:26:53Z")\
**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 16, 2017, 7:26pm UTC](https://discourse.codecombat.com/t/how-to-pass-blind-distance/13290/1 "2017-12-16T19:26:53Z")

</div>

I don’t know how to pass this level. Can anyone help?  
Here is my code :

# Tell the wizard the distance to the coming ogres.

# This function finds the nearest enemy and returns the distance to it.

# If there is no enemy, the function returns 0.

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.  
distance = nearestEnemyDistance()  
# If the enemyDistance is greater than 0:  
if distance \> 0 :  
# Say the value of enemyDistance variable.  
hero.say(“distance”)

I think this is complicated 🙂

---

<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 16, 2017, 8:14pm UTC](https://discourse.codecombat.com/t/how-to-pass-blind-distance/13290/2 "2017-12-16T20:14:22Z")

</div>

You have defined the variable distance. Then when you call the variable with the hero.say method, you call it as a string. Once defined, a variable is not a string.

---

<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:30am UTC](https://discourse.codecombat.com/t/how-to-pass-blind-distance/13290/3 "2017-12-19T00:30:01Z")

</div>

I don’t know what is a string XD  
Can you explain?

---

<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 19, 2017, 1:05am UTC](https://discourse.codecombat.com/t/how-to-pass-blind-distance/13290/4 "2017-12-19T01:05:02Z")

</div>

**String** - a type of programming data that represents text.

**Variable** - a symbol that represents data.

In your case, you have defined the variable distance as the function, nearestEnemyDistance().

```python
distance = nearestEnemyDistance()

```

A variable is not just a string of text, it is a value of data. When you use the method, hero.say(), you call the variable as a string, which, to the program, is just a bunch of letters with no meaning and no value. It is a string because it is in quotes. No quotes - it’s a variable. With quotes - it’s a string.

 ![PythonPosterOriginal_Page2](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/3/3f791592d47dfaa4352fddbc1f2c3a94a80e95c1.jpg)  
 ![PythonPosterOriginal_Page3](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/3/339bd52fb69276a7d9f967b3c11ea5560cc8c73e.jpg)

---

<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, 5:10am UTC](https://discourse.codecombat.com/t/how-to-pass-blind-distance/13290/5 "2017-12-19T05:10:37Z")

</div>

Thank you for sending me this. I worked on it, but the thing is, the blind magician just gets tired out. What should I do?

---

<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, 5:23am UTC](https://discourse.codecombat.com/t/how-to-pass-blind-distance/13290/6 "2017-12-19T05:23:44Z")

</div>

I just figured it out!  
THANK YOU SO MUCH!

---

<div class="post-metadata">

**Author:** ![Student\_Spencer\_Bull](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/student_spencer_bull/32/11145_2.png) [@Student\_Spencer\_Bull](https://discourse.codecombat.com/u/Student_Spencer_Bull)\
**Post date:** [April 9, 2020, 1:49am UTC](https://discourse.codecombat.com/t/how-to-pass-blind-distance/13290/7 "2020-04-09T01:49:42Z")

</div>

Mod edit: Please refrain from posting solutions

---

<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:** [April 9, 2020, 10:27am UTC](https://discourse.codecombat.com/t/how-to-pass-blind-distance/13290/8 "2020-04-09T10:27:07Z")

</div>

Hi @Student_Spencer_Bull, welcome to the CodeCombat Discourse. 🎉  
Nice code! I like your use of a function. But if it’s alright please could you remove the complete solution, as it’s against the purpose of the forum. Here we just try and help people with their code rather than post solutions.  
Thanks  
Danny

---

<div class="post-metadata">

**Author:** ![Jessie](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/jessie/32/21639_2.png) [@Jessie](https://discourse.codecombat.com/u/Jessie)\
**Post date:** [March 25, 2021, 12:00pm UTC](https://discourse.codecombat.com/t/how-to-pass-blind-distance/13290/9 "2021-03-25T12:00:29Z")

</div>

oh thank you I was stuck on this level for like forever thankyouthankyouthankyou!!!

---

<div class="post-metadata">

**Author:** ![milton.jinich](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/milton.jinich/32/21419_2.png) [@milton.jinich](https://discourse.codecombat.com/u/milton.jinich)\
**Post date:** [March 25, 2021, 12:03pm UTC](https://discourse.codecombat.com/t/how-to-pass-blind-distance/13290/10 "2021-03-25T12:03:37Z")

</div>

Hello and welcome to codecombat discourse! This is a cozy forum where you can share ideas, share fan art, get assistance for code, etc! Before you proceed, we hope that you review [this topic](https://discourse.codecombat.com/t/welcome-to-codecombat-discourse-forums/15601), which shows all essentials of this board! Thanks!

---

<div class="post-metadata">

**Author:** ![Egirl](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/egirl/32/17906_2.png) [@Egirl](https://discourse.codecombat.com/u/Egirl)\
**Post date:** [May 14, 2021, 1:58pm UTC](https://discourse.codecombat.com/t/how-to-pass-blind-distance/13290/11 "2021-05-14T13:58:37Z")

</div>

hello i need some help

```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.
distance = nearestEnemyDistance()
# If the enemyDistance is greater than 0:
if distance > 0 :
# Say the value of enemyDistance variable.
hero.say(“distance”)

```

---

<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:** [May 15, 2021, 4:34am UTC](https://discourse.codecombat.com/t/how-to-pass-blind-distance/13290/12 "2021-05-15T04:34:01Z")

</div>

First of all, you need to indent your code, otherwise parts of your code will not run correctly. Please check that all of your code is correctly indented. Second, in the last line, you are calling `hero.say(“distance”)`, but that is making your hero say the string-form of `distance`, not the variable. Remove the quotes and it should work.

---

<div class="post-metadata">

**Author:** ![Egirl](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/egirl/32/17906_2.png) [@Egirl](https://discourse.codecombat.com/u/Egirl)\
**Post date:** [May 21, 2021, 11:47pm UTC](https://discourse.codecombat.com/t/how-to-pass-blind-distance/13290/13 "2021-05-21T23:47:02Z")

</div>

Hi again, i did what you said but it didnt work! ☹ It seems to be the return result.

```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(Distance)

```

---

<div class="post-metadata">

**Author:** ![Egirl](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/egirl/32/17906_2.png) [@Egirl](https://discourse.codecombat.com/u/Egirl)\
**Post date:** [May 21, 2021, 11:47pm UTC](https://discourse.codecombat.com/t/how-to-pass-blind-distance/13290/14 "2021-05-21T23:47:42Z")

</div>

I did the indent too its just not working!

---

<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:** [May 23, 2021, 9:44am UTC](https://discourse.codecombat.com/t/how-to-pass-blind-distance/13290/15 "2021-05-23T09:44:10Z")

</div>

Replace `hero.say(Distance)` with `hero.say(enemyDistance)`

---

<div class="post-metadata">

**Author:** ![Ashton\_Gifford](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ashton_gifford/32/24614_2.png) [@Ashton\_Gifford](https://discourse.codecombat.com/u/Ashton_Gifford)\
**Post date:** [May 25, 2021, 2:01pm UTC](https://discourse.codecombat.com/t/how-to-pass-blind-distance/13290/16 "2021-05-25T14:01:05Z")

</div>

i cant do it. its keep saying: There is no enemy. Use enemy = hero.findNearestEnemy() first. pls help. this is my code:

```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.
   distance = nearestEnemyDistance()
# If the enemyDistance is greater than 0:
if distance > 0 :
# Say the value of enemyDistance variable.
   hero.say(enemyDistance)

```

---

<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:** [May 25, 2021, 3:31pm UTC](https://discourse.codecombat.com/t/how-to-pass-blind-distance/13290/17 "2021-05-25T15:31:18Z")

</div>

> [@Ashton\_Gifford](#):
>
> ```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.
> distance = nearestEnemyDistance()
> # If the enemyDistance is greater than 0:
> if distance > 0 :
> # Say the value of enemyDistance variable.
> hero.say(enemyDistance)
> 
> ```

Hi @Ashton_Gifford, welcome to the forum 🎉!  
The problem here is that you’ve used two variables for what should be the same variable. The comments tell you to create a variable called enemyDistance here:

> [@Ashton\_Gifford](#):
>
> ```python
> # save the result in the variable enemyDistance.
> 
> ```

However, you called yours distance:

> [@Ashton\_Gifford](#):
>
> `distance = nearestEnemyDistance()`

That would be fine, as long as you are _consistent_. Here, you used enemyDistance, which you haven’t defined!

> [@Ashton\_Gifford](#):
>
> `hero.say(enemyDistance)`

You don’t need to redefine enemyDistance as distance necessarily, but what you do have to do is make sure both of those variables (distance and enemyDistance) have _the same name_. They’re supposed to be exactly the same thing.  
I hope this helps.  
Danny

---

<div class="post-metadata">

**Author:** ![Ashton\_Gifford](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ashton_gifford/32/24614_2.png) [@Ashton\_Gifford](https://discourse.codecombat.com/u/Ashton_Gifford)\
**Post date:** [May 25, 2021, 3:37pm UTC](https://discourse.codecombat.com/t/how-to-pass-blind-distance/13290/18 "2021-05-25T15:37:56Z")

</div>

@Deadpool198 its still telling me the thing about the enemy variable. what do i do about that?

---

<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:** [May 25, 2021, 4:27pm UTC](https://discourse.codecombat.com/t/how-to-pass-blind-distance/13290/19 "2021-05-25T16:27:35Z")

</div>

Please could you post your new code. I may not have told you what I meant properly, but I did test it with my change and it did work, so you may not have made the right change.  
Danny

---

<div class="post-metadata">

**Author:** ![Ashton\_Gifford](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ashton_gifford/32/24614_2.png) [@Ashton\_Gifford](https://discourse.codecombat.com/u/Ashton_Gifford)\
**Post date:** [May 25, 2021, 6:26pm UTC](https://discourse.codecombat.com/t/how-to-pass-blind-distance/13290/20 "2021-05-25T18:26:06Z")

</div>

here’s my code:

`# Tell the wizard the distance to the coming ogres.

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 enemydistance \> 0 :

# Say the value of enemyDistance variable.

hero.say(enemydistance)  
`

```python
i changed it to say enemydistance instead of distance. is that what you told me to do?
```

[Next page](https://discourse.codecombat.com/t/how-to-pass-blind-distance/13290.md?page=2)
