Bookkeeper problem with coin count(python)


I have problem counting the number of coins the hero collected. The hero collected 16 coins but he said he collected 13. What is the problems of my code?
Hero is my code in coin counting

collected = 0
while True:
coin = hero.findNearestItem
if coin:
hero.moveXY(coin.pos.x, coin.pos.y)
collected += coin.value
if hero.time > 30

hero.move(59, 33)


Please format you code according to the FAQ.


Use to watch for you gold instead count it.


thx… I solved it ,But y i can’t count it as Hoarding Gold level does?


Looks careful for your hero – sometimes you collect coins while your hero is moving for another one. As the result you don’t count coins which you take occasionally


IC,thx so much…


Yeah! I had the same problem.


Sorry for resurrecting and old thread, but I think I may have something to add here:
In “Hoarding Gold” (the level before Bookkeeper), gold is counted using a variable totalGold and += :

totalGold = 0
while True:
    coin = hero.findNearestItem()
    if coin:
        # Sammle die Münzen auf.
        hero.moveXY(coin.pos.x, coin.pos.y)
        # Addiere den Münzwert (value) zur Goldsumme (totalGold) hinzu. (für mehr Details siehe Anleitung)
        totalGold += coin.value
        # Erhalte seinen Wert mit:  coin.value
    if totalGold >= 25:
        # Dies bricht aus der Schleife aus und fährt mit dem Code darunter fort.
        # Die Schleife ist beendet, jetzt wird der Code nach der Schleife ausgeführt.

Also, the hints for this level suggest to report the final amount of gold using the variable totalGold:

And in “Bookkeeper”, the counting method is used again for number of defeated enemys:

defeated = 0
while True:
    enemy = hero.findNearestEnemy()
    if enemy:
        if <= 0:
            defeated += 1

I believe it would come natural to most people that they should use the same technique for counting the coins - and reporting it to Naria! That also resulted for me in this perceived bug of hero reporting the counted gold instead of current amount => wrong, because he had collected an extra coin in passing, like you said:

The function isn’t explicitly mentioned/explained, so maybe it would be a good idea to say it in the hints that counting isn’t necessary in this level and people won’t run into this problem anymore - or more postings for this topic :wink: