[Solved] Wishing Well (HELP NEEDED)

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

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

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

Guys i need help @everyone

Don’t worry I just solved it.

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.

# 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

it says ran out of time.

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

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

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.

i got this # 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():
pass
and im confused it isn’t working

Hi @dragonsboy0, welcome to the forum! :tada:
Please could you post your code formatted so we can see the spaces. To format code you put three ``` (backticks not quotes) on a new line at the start and end of your code to format it.
Danny

less = “Nimis”
more = “Non satis”
requiredGold = 104

This function calculates the sum of coin values.

def sumCoinValues(coins):
i = 0
total = 0
while i < len(coins):
total += coins[i].value
i += 1
return total

while True:
items = hero.findItems()
goldAmount = sumCoinValues(items)
if len(items) != 0:
# If there is not enough gold, then say “Non satis”.
if goldAmount > 104:
# If there is too much gold, then say “Nimis”.
hero.say(less)
# If there is exactly 104 gold, then collect all coins.
if goldAmount < 104:
hero.say(more)
pass
if goldAmount == 104:
break
while True:
items = hero.findItems()
item = hero.findNearest(items)
if item:
hero.moveXY(41, 19)
hero.moveXY(55, 18)
hero.moveXY(60, 29)
hero.moveXY(41, 19)
hero.moveXY(51, 46)
hero.moveXY(58, 34)
hero.moveXY(20, 40)
hero.moveXY(24, 18)
hero.moveXY(40, 46)
hero.moveXY(33, 45)
hero.moveXY(25, 35)
hero.moveXY(35, 18)
hero.moveXY(28, 25)
hero.moveXY(32, 19)
hero.moveXY(38, 25)
hero.moveXY(59, 44)
hero.moveXY(27, 18)
hero.moveXY(24, 46)
hero.moveXY(53, 33)

this?

no i did it wrong man how do u do it ? sorry

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


# This function calculates the sum of coin values.
def sumCoinValues(coins):
    i = 0
    total = 0
    while i < len(coins):
        total += coins[i].value
        i += 1
    return total


while True:
    items = hero.findItems()
    goldAmount = sumCoinValues(items)
    if len(items) != 0:
        # If there is not enough gold, then say "Non satis".
        if goldAmount > 104:
            # If there is too much gold, then say "Nimis".
            hero.say(less)
        # If there is exactly 104 gold, then collect all coins.
        if goldAmount < 104:
            hero.say(more)
        pass
        if goldAmount == 104:
            break
while True:
    items = hero.findItems()
    item = hero.findNearest(items)
    if item:
        hero.moveXY(41, 19)
        hero.moveXY(55, 18)
        hero.moveXY(60, 29)
        hero.moveXY(41, 19)
        hero.moveXY(51, 46)
        hero.moveXY(58, 34)
        hero.moveXY(20, 40)
        hero.moveXY(24, 18)
        hero.moveXY(40, 46)
        hero.moveXY(33, 45)
        hero.moveXY(25, 35)
        hero.moveXY(35, 18)
        hero.moveXY(28, 25)
        hero.moveXY(32, 19)
        hero.moveXY(38, 25)
        hero.moveXY(59, 44)
        hero.moveXY(27, 18)
        hero.moveXY(24, 46)
        hero.moveXY(53, 33)
        

ok i did it

Screenshot 2020-10-29 at 10.23.16 AM
Screenshot 2020-10-29 at 10.19.44 AM

Delete this:

and this:

Delete an indent in this part:

Replace all 104 with requiredGold

Should be Non satis:

Should be Nimis:

Replace with

this:

coin = hero.findNearestItem()
            while coin:
                
                # Then collect all coins:
                hero.moveXY(coin.pos.x, coin.pos.y)
                coin = hero.findNearestItem()
                
        pass

Lydia

1 Like

ok lemme try this
yeah it worked your the best thx

1 Like

No problem! Glad to hear you passed!
Lydis

Hi i need help for the same level heres 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:
    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:
            return collectAllCoins()
        pass

it keeps adding up to 190 help pls