I subscribed and I recently got pender but I can not beat mad maxer this is my code in python can someone fix it?
# You can't reach your friends to defend them!
# Tell them to go home where the archer can help.
while True:
weakestFriend = None
leastHealth = 9999
friendIndex = 0
# Find which friend has the lowest health.
while friendIndex<len(weakestFriend):
weakestFriend=friends[leastHealth]
if weakestFriend:
hero.say('Hey ' + weakestFriend.id + ', go home!')
friendIndex+=1
Well, you’re using leastHealth for index, instead of friendIndex …
You’re supposed to go through the list of friends (something like friend = friends[index]) and update the weakestFriend and leastHealth variables when you find a friend that has less health than the current weakest friend. When you went through all of them, you have the weakest friend stored in weakestFriend
I’m stuck on this level as well. I think I have the read of the array and the assignment of weakestFriend running correctly, but when the hero calls the friends’ names, they don’t run. Anyone else running into this? Have any ideas?
Here’s what I’m using:
while True:
weakestFriend = None
leastHealth = 9999
friendIndex = 0
# Find which friend has the lowest health.
friends = hero.findFriends()
while friendIndex < len(friends):
friend = friends[friendIndex]
if friend.health < leastHealth:
weakestFriend = friend
leastHealth = friend.health
friendIndex += 1
# Tell the weakest friends to go home first.
if weakestFriend:
hero.say('Hey ' + weakestFriend.id + ', go home!')