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
# 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
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
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!
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)
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)
# 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