Needing help for Level 47 Keeping time CS3

Use your new skill to choose what to do: hero.time

while True:
# If it’s the first 10 seconds, attack.
if hero.time < 10:
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
# Else, if it’s the first 35 seconds, collect coins.
elif hero.time < 35:
coin = hero.findNearestItem()
if coin:
hero.moveXY(coin.pos.x, coin.pos.y)
# After 35 seconds, attack again!
else:
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)

My code seems to be correct, used all the characters but they all just die at last second. Anyone know how to fix this?