Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Diamond Dozen (HELP NEEDED)


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 > targetHealth:
target = enemy
targetHealth =
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 > 15:
while > 0:
coins = hero.findItems()
coin = None
coin = findBestItem(coins)
if coin:
hero.moveXY(coin.pos.x, coin.pos.y)

Also, here’s a picture:


Nooo! Plz use </> or I will faint

1 Like

Format your code!!! PLZLZLLZ

1 Like

It says loop over the array. (for loop)

You know what the problem is?

You spelled valueOverDistance wrong…


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.