Bookkeeper Help!

My code is correct but every time I pass over a coin that isn’t labeled “item” it doesn’t count toward my “totalGold”… how do I fix that??

# This function allows to fight until the certain time
# and report about defeated enemies.
def fightAndReport(untilTime):
    defeated = 0
    while True:
        enemy = hero.findNearestEnemy()
        if enemy:
            if <= 0:
                defeated += 1
        if hero.time > untilTime:
    hero.moveXY(59, 33)

# Fight 15 seconds and tell Naria how many enemies you defeated.

# Collect coins until the clock reaches 30 seconds.
def collectCoins(untilTime):
    totalGold = 0
    while True:
        item = hero.findNearestItem()
        if item:
            hero.moveXY(item.pos.x, item.pos.y)
            totalGold += item.value
        if hero.time > untilTime:
    hero.moveXY(59, 33)




i think it maybe be that u need to define both
else IDK

:frowning_face: :frowning_face: I got it, but not in submit so it didn’t count!!

define both of what though?


(20 doritos)

Hi @CranKeD_Wired,
the problem here is that you use a totalGold variable. In theory it works, but in practice what happens is that your hero collects two coins at once, and because of the way your code works it thinks it’s only collected one. Hence the wrong number at the end. Instead you can just the built in gold variable :wink:.
By the way I really like your code, well done for using functions and the totalGold variable. It’s very neat. It’s just that the variable doesn’t work in this specific level.
I hope this solves your problem,

1 Like

so instead of doing totalGold = 0 and totalGold += item.value, I should do = 0 and += item.value? Also, thank you for the compliments!

oh I got it! Thank you sm!!

1 Like