Mmmmmm I tried my best…
i think the website is faulty.
What is UAdd??
I searched google and there was just no result.
The only thing i say is some Arabic website which i don’t even understand.
Can someone help me?
The level is the dessert Brittle Morale
i don’t know if im being stupid or not but here is my code
# You have one arrow. Make it count!
# This should return the enemy with the most health.
def findStrongestEnemy(enemies):
strongest = None
strongestHealth = 0
enemyIndex = 0
# While enemyIndex is less than the length of enemies:
while enemyIndex < len(enemies):
enemy = hero.findNearestEnemy
# Set an enemy variable to enemies[enemyIndex]
enemies[enemyIndex] = enemy
# If enemy.health is greater than strongestHealth
if enemy.health > strongestHealth:
# Set `strongest` to enemy
# Set strongestHealth to enemy.health
strongestHealth = enemy.health
strongest = enemy
# Increment enemyIndex
enemyIndex += 1
return strongest
enemies = hero.findEnemies()
leader = findStrongestEnemy(enemies)
if leader:
hero.say(leader)
thanks.
so did solve it if yes, yay, else, nooo
You’ve almost got it. The problem is that you are defining enemy and enemies incorrectly. You first define enemies at the bottom of the code; you then pass this object to the findStrongestEnemy function when you define ‘leader’. In the function, you start iterating through the array ‘enemies’…this is all good.
However, you then define enemy as the closest enemy…this will always be just one enemy and very likely the same one every time. Also, you have your enemy definition transposed. See the comments:
while enemyIndex < len(enemies):
enemy = hero.findNearestEnemy ### delete this entire line
# Set an enemy variable to enemies[enemyIndex]
enemies[enemyIndex] = enemy ### these are backwards
# If enemy.health is greater than strongestHealth
if enemy.health > strongestHealth:
# Set `strongest` to enemy
# Set strongestHealth to enemy.health
strongestHealth = enemy.health
strongest = enemy
# Increment enemyIndex
enemyIndex += 1
return strongest
Everything else looks good
I dont do python but i wanna learn it one day
well its easy for me i think you will like it, Jeremy_Yu, and thanks for the help dedreous… again
I look forward to learning