# Bookkepper help! plz

help my code is not working, I do not collect the coins.

``````# Fight enemies for 15 seconds.
# Keep count whenever an enemy is defeated.
defeated = 0
while True:
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
if enemy.health <= 0:
defeated += 1
if hero.time > 15:
break

# Tell Naria how many enemies you defeated.
hero.moveXY(59, 33)
hero.say(defeated)

# Collect coins until the clock reaches 30 seconds.
while True:
item = hero.findNearestItem()
if item:
pos = item.pos
x = pos.x
y = pos.y

# Tell Naria how much gold you collected.
while True:
hero.moveXY(59, 33)
hero.say(hero.gold)

def fightAndReport(untilTime):
defeated = 0
while True:
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
if enemy.health <= 0:
defeated += 1
if hero.time > untilTime:
break
hero.moveXY(59, 33)
hero.say(defeated)

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

# Collect coins until the clock reaches 30 seconds.
findAndReport(30)

# Tell Naria how much gold you collected.
hero.say(hero.gold)

# Fight enemies until the clock reaches 45 seconds.
fightAndReport(45)
``````

You never told the hero to collect the coins using `hero.moveXY(coin.pos,x,coin.pos.y)`. Also you don’t want the hero.moveXY(59, 33) and hero.say(hero.gold) in a while True loop.

my code now there’s no difference to the act

``````# 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:
hero.attack(enemy)
if enemy.health <= 0:
defeated += 1
if hero.time > untilTime:
break
hero.moveXY(59, 33)
hero.say(defeated)

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

# Collect coins until the clock reaches 30 seconds.
# This function allows to fight until the certain time
# and report about defeated enemies.
if hero.time == 15:
def collectAndReport(untilTime):
collected == 0
while True:
item = hero.findNearestItem()
if item:
hero.moveXY(item.pos.x, item.pos.y)
if hero.time > untilTime:
break
hero.moveXY(59, 33)
hero.say(collected)

``````

There’s no point in creating a function in an if statement.

``````# 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:
hero.attack(enemy)
if enemy.health <= 0:
defeated += 1
if hero.time > untilTime:
break
hero.moveXY(59, 33)
hero.say(defeated)

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

# Collect coins until the clock reaches 30 seconds.
# This function allows to fight until the certain time
# and report about defeated enemies.
while True:
item = hero.findNearestItem()
if item:
hero.moveXY(item.pos.x, item.pos.y)
if hero.time > (untilTime):
break
hero.moveXY(59, 33)
hero.say(collected)

# Tell Naria how much gold you collected.
hero.say(hero.gold)

# Fight enemies until the clock reaches 45 seconds.
fightAndReport(45)

``````