# Level Wishing well help

Hi people of codecombat, I need help with the level Wishing well.

here is my code:

``````# You need exactly 104 gold.

less = "Nimis"
more = "Non satis"
requiredGold = 104

# This function calculates the sum of all coin values.
def sumCoinValues(coins):
coinIndex = 0
totalValue = 0
# Iterate all coins.
while coinIndex < len(coins):
totalValue += coins[coinIndex].value
coinIndex += 1

def collectAllCoins():
item = hero.findNearest(hero.findItems())
while item:
hero.moveXY(item.pos.x, item.pos.y)
item = hero.findNearest(hero.findItems())

while True:
coin = hero.findItems()
# Get the total value of coins.
goldAmount = sumCoinValues(items)
# If there are coins, then goldAmount isn't zero.
if goldAmount != 0:
# If goldAmount is less than requiredGold
if goldMount < requiredGold:
# Then say "Non satis".
hero.say(less)
# If goldAmount is greater than requiredGold
if goldMount > requiredGold:
# Then say "Nimis".
hero.say(more)
# If goldAmount is exactly equal to requiredGold
if goldAmount == requiredGold:
# Then collect all coins:
hero.moveXY(coin.pos.x, coin.pos.y)
pass

``````

Thank you.

``````if goldMount < requiredGold:
``````
``````if goldMount > requiredGold:
``````

But you started by defining it as:

``````goldAmount = sumCoinValues(items)
``````
2 Likes

Also check whether you’re using ‘coin’ or ‘items’:

``````    coin = hero.findItems()
# Get the total value of coins.
goldAmount = sumCoinValues(items)
``````

Jenny

2 Likes

Can you send the link for this level?
Lydia

1 Like
2 Likes

Try fixing what Jenny said to fix, it should work after that.
Lydia

1 Like

Still doesn’t work.

here is my code:

``````# You need exactly 104 gold.

less = "Nimis"
more = "Non satis"
requiredGold = 104

# This function calculates the sum of all coin values.
def sumCoinValues(coins):
coinIndex = 0
totalValue = 0
# Iterate all coins.
while coinIndex < len(coins):
totalValue += coins[coinIndex].value
coinIndex += 1

def collectAllCoins():
item = hero.findNearest(hero.findItems())
while item:
hero.moveXY(item.pos.x, item.pos.y)
item = hero.findNearest(hero.findItems())

while True:
coin = hero.findItems()
# Get the total value of coins.
goldAmount = sumCoinValues(coin)
# If there are coins, then goldAmount isn't zero.
if goldAmount != 0:
# If goldAmount is less than requiredGold
if goldAmount < requiredGold:
# Then say "Non satis".
hero.say(less)
# If goldAmount is greater than requiredGold
if goldAmount > requiredGold:
# Then say "Nimis".
hero.say(more)
# If goldAmount is exactly equal to requiredGold
if goldAmount == requiredGold:
# Then collect all coins:
hero.moveXY(coin.pos.x, coin.pos.y)
pass
``````

Remember you’ve got a function for collecting all the coins. Use it!
Jenny

2 Likes

I looked at my brother’s account and now i know what is the problem