# I post to many topics. Weakest Quickest help please! [Solved]

``````def findWeakestEnemy():
enemies = hero.findEnemies()
weakest = None
leastHealth = 99999
enemyIndex = 0
while enemy.Index < len(enemies):
enemy = enemies[enemyIndex]
if enemies.health < leastHealth:
weakest = enemy
leastHealth = enemy.health
return weakest

while True:
enemy = findWeakestEnemy
if enemy:
hero.attack(enemy)

``````

1. Itâ€™s ok to make topics because youâ€™re actually using them for good reasons.
2. Right now I canâ€™t get on our computer to do CoCo, so I canâ€™t help. Sorry.

I also tried

``````for enemy in enemies:
``````

It just doesnâ€™t work!

What is your problem or error?

My hero doesnâ€™t move. Like, at all.

I mean, I guess you could try putting hero.attack(weakest)
But idk if that would even help.

I fixed the parenthesis problem at the bottom after the function and got rid of the period in between enemy and Index at the top.

Now it says it has an infinite loop.

Was the parenthesis problem what I suggested? If so, now that youve taken the period out and it still doesnâ€™t work, put it back to `hero.attack(enemy)`

No it was to the

``````enemy = findWeakestEnemy()
``````

it at first didnâ€™t have parenthesis after it.

I like how you when I clicked on your picture it showed a summery of what you like and stuff. How do you do that?

``````def findWeakestEnemy():
enemies = hero.findEnemies()
enemyIndex = 0
weakest = None
leastHealth = 99999

while enemyIndex < len(enemies):
enemy = enemies[enemyIndex]
if enemies.health < leastHealth:
weakest = enemy
leastHealth = enemy.health
return weakest

while True:
enemy = findWeakestEnemy()
if enemy:
hero.attack(enemy)
``````

How should I solve the infinite loop problem?

First of all, I asked you to ignore what I said about switching around the ` enemyIndex = 0`
Secondly, Iâ€™m comparing your code with mine in Brittle Morale. In Brittle morale youâ€™re doing the exact same thing but with strongest health. Youâ€™re switching back and forth from weakest to least. I feel like you should just stick with weakest.

Oh, and enemies should just be enemy.

I might be wrong about the least health. It is a different level Iâ€™m comparing it to, after all. But I think itâ€™s worth a try.

but sence I did this

``````enemies = hero.findEnemies()
``````

instead of enemy. Shouldnâ€™t i keep it like it was?

I honestly think it should be `enemy = hero.findEnemies()`

Hahaha. I did that and there were like, twenty errors poping up.

1 Like