# \[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:** 2

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

</div>

> [@MunkeyShynes](#):
>
> . . .and this variable should be the argument in the `hero.say` method

The argument is what is inside the parenthesis of the method.

 ![PythonPosterOriginal_Page2](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/e/e76b9d50279ee7e856c5573faff8fdc4a3cccba1.jpeg)

You have not done the second part of my initial post. You do not need to define your variable twice.

---

<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 11, 2019, 9:56pm UTC](https://discourse.codecombat.com/t/solved-python-blind-distance/11338/22 "2019-03-11T21:56:51Z")

</div>

Hello @MunkeyShynes I have done some trial and error with the information an I finally got my mage to Attack, so thank you very much for you help!  
I’m only a beginner so I am sorry if I made you loose time with me and my misunderstandings.  
Again, Thank you very much.

---

<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 11, 2019, 10:16pm UTC](https://discourse.codecombat.com/t/solved-python-blind-distance/11338/23 "2019-03-11T22:16:57Z")

</div>

@MunkeyShynes I have yet another problem but now that I understand more I think I will figure this out easier so my mage attack but 4 seconds before the code finishes, it says it gets too tired and it stops attacking. here 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
    enemyDistance = nearestEnemyDistance()
    # If the enemyDistance is greater than 0: 
    if enemyDistance > 0 : 
        enemyDistance
        # Say the value of enemyDistance variable.
        hero.say("15")

```

I would appreciate your help once again!

---

<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 11, 2019, 11:15pm UTC](https://discourse.codecombat.com/t/solved-python-blind-distance/11338/24 "2019-03-11T23:15:41Z")

</div>

> [@MunkeyShynes](#):
>
> . . .and this variable should be the argument in the `hero.say` method.

You still haven’t done this.

---

<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 12, 2019, 12:18am UTC](https://discourse.codecombat.com/t/solved-python-blind-distance/11338/25 "2019-03-12T00:18:08Z")

</div>

I am sorry I am still confused wasn’t the `hero.say` part so that the wizard would attack?  
Would you mind explaining me what my problem is in another way?

---

<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 12, 2019, 1:00am UTC](https://discourse.codecombat.com/t/solved-python-blind-distance/11338/26 "2019-03-12T01:00:30Z")

</div>

Presently, the argument for the hero.say method is a string - “15”

You should be calling your enemyDistance variable as the argument.

Also, immediately after the `if enemyDistance` conditional statement, you call your variable but for no reason. That line should not be there. It does nothing.

---

<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 12, 2019, 9:16pm UTC](https://discourse.codecombat.com/t/solved-python-blind-distance/11338/27 "2019-03-12T21:16:26Z")

</div>

Munkey Shynes, when you say ‘calling your enemyDistance’ do you mean that my character should say that?  
Calling = Saying?

---

<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 13, 2019, 12:02am UTC](https://discourse.codecombat.com/t/solved-python-blind-distance/11338/28 "2019-03-13T00:02:41Z")

</div>

Why don’t you try it and find out? 😀

---

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

</div>

Hi @MunkeyShynes I tried `hero.say enemyDistance` which is what you said (or at least I think so)  
but the wizard says “say a number!” so I tried making a few tweaks to the code : still no result.😥Here is my actual code with the `hero.say enemyDistance`

```python
def nearestEnemyDistance():
    enemy = hero.findNearestEnemy()
    result = 10
    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")

```

Honestly, I don’t know what to do

---

<div class="post-metadata">

**Author:** ![ducky](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ducky/32/9364_2.png) [@ducky](https://discourse.codecombat.com/u/ducky)\
**Post date:** [March 13, 2019, 12:38am UTC](https://discourse.codecombat.com/t/solved-python-blind-distance/11338/30 "2019-03-13T00:38:09Z")

</div>

Take the quotes off enemyDistance.

---

<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 13, 2019, 12:55am UTC](https://discourse.codecombat.com/t/solved-python-blind-distance/11338/32 "2019-03-13T00:55:54Z")

</div>

@MunkeyShynes I figured out thank you so much I literally could not have done this without you.  
once again thanks!

---

<div class="post-metadata">

**Author:** ![arctic\_snow223](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/arctic_snow223/32/9931_2.png) [@arctic\_snow223](https://discourse.codecombat.com/u/arctic_snow223)\
**Post date:** [April 3, 2019, 6:17pm UTC](https://discourse.codecombat.com/t/solved-python-blind-distance/11338/33 "2019-04-03T18:17:07Z")

</div>

is some what worked for me but i died here is the imaje

 ![35%20PM](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/2/2da5b45c5b12a613b304ac94a6cd2e38e0a27d98.png)

---

<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:** [April 3, 2019, 7:42pm UTC](https://discourse.codecombat.com/t/solved-python-blind-distance/11338/35 "2019-04-03T19:42:09Z")

</div>

All default comments deleted - your code without changes:

```python
def nearestEnemyDistance():
    enemy = hero.findNearestEnemy()
    result = 10 # you set the default distance to enemy to 10
    if enemy: # and if there is no enemy
        result = hero.distanceTo(enemy)
    return result # the distance to enemy will be 10
                  # if there is no enemy
while True:
    enemyDistance = nearestEnemyDistance()
    if enemyDistance > 0: # this will be always true
                          # 10 or the real distance
        hero.say(enemyDistance)

```

Question 1: is this line really needed?

```python
result = 10 # or some other value

```

Can we comment it?  
Question 2: Can we write only?:

```python
 if enemyDistance: # without comparing enemyDistance to 0?

```

---

<div class="post-metadata">

**Author:** ![arctic\_snow223](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/arctic_snow223/32/9931_2.png) [@arctic\_snow223](https://discourse.codecombat.com/u/arctic_snow223)\
**Post date:** [April 4, 2019, 5:33pm UTC](https://discourse.codecombat.com/t/solved-python-blind-distance/11338/36 "2019-04-04T17:33:20Z")

</div>

i get it now thank you

---

<div class="post-metadata">

**Author:** ![Dae\_Shaun\_High\_Hawk](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dae_shaun_high_hawk/32/21794_2.png) [@Dae\_Shaun\_High\_Hawk](https://discourse.codecombat.com/u/Dae_Shaun_High_Hawk)\
**Post date:** [December 16, 2019, 11:41pm UTC](https://discourse.codecombat.com/t/solved-python-blind-distance/11338/37 "2019-12-16T23:41:37Z")

</div>

> [@Franz](#):
>
> hero.say(“enemyDistance”)

that actually helped me alot thank you it took me 2 days to figure it out thanks for the advice  
👍 👍

---

<div class="post-metadata">

**Author:** ![YaYeetingBOI](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/yayeetingboi/32/11692_2.png) [@YaYeetingBOI](https://discourse.codecombat.com/u/YaYeetingBOI)\
**Post date:** [March 31, 2020, 6:05pm UTC](https://discourse.codecombat.com/t/solved-python-blind-distance/11338/38 "2020-03-31T18:05:29Z")

</div>

for some reason my wizard continuously attacks

---

<div class="post-metadata">

**Author:** ![YaYeetingBOI](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/yayeetingboi/32/11692_2.png) [@YaYeetingBOI](https://discourse.codecombat.com/u/YaYeetingBOI)\
**Post date:** [March 31, 2020, 6:06pm UTC](https://discourse.codecombat.com/t/solved-python-blind-distance/11338/39 "2020-03-31T18:06:06Z")

</div>

here is my code`

````python
type or paste code here
```def nearestEnemyDistance():
    enemy = hero.findNearestEnemy()
    result = 10
    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)
````

---

<div class="post-metadata">

**Author:** ![ZAX155](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/zax155/32/34141_2.png) [@ZAX155](https://discourse.codecombat.com/u/ZAX155)\
**Post date:** [April 1, 2020, 4:50pm UTC](https://discourse.codecombat.com/t/solved-python-blind-distance/11338/40 "2020-04-01T16:50:17Z")

</div>

@dedreous @ducky @CodingGeek14

```python
def nearestEnemyDistance():
    enemy = hero.findNearestEnemy()
    result = 10
    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")

```

---

<div class="post-metadata">

**Author:** ![dedreous](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dedreous/32/13849_2.png) [@dedreous](https://discourse.codecombat.com/u/dedreous)\
**Post date:** [April 1, 2020, 5:12pm UTC](https://discourse.codecombat.com/t/solved-python-blind-distance/11338/41 "2020-04-01T17:12:29Z")

</div>

The problem is with line 3 and 14. As written, line 3 will make enemyDIstance always \> 0. What happens if there is no enemy…what is the value of result then?

Line 14, as written, is having the hero say a literal string value (which will always be “enemyDistance”), not the value of the variable…lose the quotation marks.

---

<div class="post-metadata">

**Author:** ![ZAX155](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/zax155/32/34141_2.png) [@ZAX155](https://discourse.codecombat.com/u/ZAX155)\
**Post date:** [April 1, 2020, 5:16pm UTC](https://discourse.codecombat.com/t/solved-python-blind-distance/11338/42 "2020-04-01T17:16:57Z")

</div>

okay and could we talk in a dm

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

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