Level Mountain mercenaries error



I have this error in python solution:
Error Cannot read property ‘start’ of undefined

This is my code on this level:

def bestValue(item):
    return item.value / hero.distanceTo(pet.fetch(item)

def findGoodItem(items):
    g_item = items[0]
    for item in items:
        if BestValue(item)>BestValue(g_item):
            g_item = item
    return g_item

while True:
    item = findGoodItem(hero.findItems())

    if hero.gold > hero.costOf("soldier"):

    enemy = hero.findNearest(hero.findEnemies())
    if enemy:
        soldiers = hero.findFriends()
        for soldier in soldiers:
            hero.command(soldier, "attack", enemy

        while enemy.health>0:


return item.value / hero.distanceTo(pet.fetch(item)
odd number of brackets?


Thank you, It’s help!)


(Solution removed)

New code!


Please do not post working code/solutions. The purpose of this board is to help people learn and simply providing/posting completed solutions is counterproductive to that goal. Thank you.