# Diamond Dozen (HELP NEEDED)

**URL:** <https://discourse.codecombat.com/t/diamond-dozen-help-needed/15014>\
**Category:** Uncategorized\
**Created:** [June 20, 2018, 3:48am UTC](https://discourse.codecombat.com/t/diamond-dozen-help-needed/15014 "2018-06-20T03:48:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Naimaa1](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/naimaa1/32/9542_2.png) [@Naimaa1](https://discourse.codecombat.com/u/Naimaa1)\
**Post date:** [June 20, 2018, 3:48am UTC](https://discourse.codecombat.com/t/diamond-dozen-help-needed/15014/1 "2018-06-20T03:48:22Z")

</div>

Hello, i’ve been stuck on this level for a long time and finally asking for help.

Here’s my code:

def findMostHealth(enemies):  
target = None  
targetHealth = 0  
enemyIndex = 0  
while enemyIndex \< len(enemies):  
enemy = enemies[enemyIndex]  
if enemy.health \> targetHealth:  
target = enemy  
targetHealth = enemy.health  
enemyIndex += 1  
return target

def valueOverDistance(item):  
return item.value / hero.distanceTo(item)

# Return the item with the highest valueOverDistance(item)

def findBestItem(items):  
bestItem = None  
bestValue = 0  
itemsIndex = 0

```
# Loop over the items array.
# Find the item with the highest valueOverDistance()
items = hero.findItems() > vaulueOverDistance()
return bestItem

```

while True:  
enemies = hero.findEnemies()  
enemy = findMostHealth(enemies)  
if enemy and enemy.health \> 15:  
while enemy.health \> 0:  
hero.attack(enemy)  
else:  
coins = hero.findItems()  
coin = None  
coin = findBestItem(coins)  
if coin:  
hero.moveXY(coin.pos.x, coin.pos.y)

Also, here’s a picture:

 ![04%20PM](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/b/b2735435e06447f10ee815891c7d1a97df230973.jpg)

---

<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:** [June 20, 2018, 6:01am UTC](https://discourse.codecombat.com/t/diamond-dozen-help-needed/15014/2 "2018-06-20T06:01:18Z")

</div>

Nooo! Plz use \</\> or I will faint

---

<div class="post-metadata">

**Author:** ![Gamestack](https://avatars.discourse-cdn.com/v4/letter/g/76d3ee/32.png) [@Gamestack](https://discourse.codecombat.com/u/Gamestack)\
**Post date:** [June 20, 2018, 7:32pm UTC](https://discourse.codecombat.com/t/diamond-dozen-help-needed/15014/3 "2018-06-20T19:32:57Z")

</div>

Format your code!!! PLZLZLLZ

---

<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:** [June 22, 2018, 5:27pm UTC](https://discourse.codecombat.com/t/diamond-dozen-help-needed/15014/4 "2018-06-22T17:27:32Z")

</div>

> [@Naimaa1](#):
>
> def findBestItem(items):  
> bestItem = None  
> bestValue = 0  
> itemsIndex = 0
> 
> ```python
> # Loop over the items array.
> # Find the item with the highest valueOverDistance()
> items = hero.findItems() > vaulueOverDistance()
> return bestItem
> 
> ```

It says loop over the array. (for loop)

You know what the problem is?

You spelled valueOverDistance wrong…

![Misspelling](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/8/8f4ec596ca2a925b4d3f66688c2589d1f2452e96.PNG)

Also there isn’t an input argument when you called on the valueOverDistance function. put the item you are looping over in the for loop in the input of valueOverDistance.
