Wishing Well (HELP NEEDED)


#1

Hello, I was wondering if you could help me out with this level and i’m not sure what i’m doing wrong.

Here’s 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
    return totalValue

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

while True:
    items = 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 goldAmount < requiredGold:
            # Then say "Non satis".
            hero.say("Non satis")
        # If goldAmount is greater than requiredGold
        if goldAmount > requiredGold:
            # Then say "Nimis".
            hero.say("Nimis")
        # If goldAmount is exactly equal to requiredGold
        if goldAmount != requiredGold:
            # Then collect all coins:
            items = hero.findItems()
        pass

#2

One you are saying != requiredGold and second you are not calling on the function for requiredGold. Firt put the != to == then call on the collectAllCoins function @Naimaa1


#3

Okay I fixed it, but it still says it’s wrong.

Here’s 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
    return totalValue

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

while True:
    items = 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 goldAmount < requiredGold:
            # Then say "Non satis".
            hero.say("Non satis")
        # If goldAmount is greater than requiredGold
        if goldAmount > requiredGold:
            # Then say "Nimis".
            hero.say("Nimis")
        # If goldAmount is exactly equal to requiredGold
        if goldAmount == requiredGold:
            # Then collect all coins:
            collectAllCoins():
                items = hero.findItems()
            pass

#4

Guys i need help @everyone


#5

Don’t worry I just solved it.


#6

Look at this line:

This doesn’t make sense, you can’t put a colon behind a function, in fact you don’t even need it, or the items = hero.findItems(). It works fine apart from that.


#7
# 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
    return totalValue

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

while True:
    items = 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 goldAmount < requiredGold:
            # Then say "Non satis".
            hero.say("Non satis")
        # If goldAmount is greater than requiredGold
        if goldAmount > requiredGold:
            # Then say "Nimis".
            hero.say("Nimis")
        # If goldAmount is exactly equal to requiredGold
        if goldAmount == requiredGold:
            # Then collect all coins:
            items = hero.findItems()
            pass


#8

it says ran out of time.


#9

No, I meant keep the “collect coins” and get rid of the items = hero.findItems() and the colon.


#10

Yea i agree. Sorry i couldn’t have helped sooner. I was away


#11

Look at the goldAmount == requiredGold if loop.

It says to collect all the coins.

You didn’t do that.

Of course it runs out of time.

Did you solve the problem yet? If so, please tell us so that we can mark the topic as solved.