I cant beat mad maxer redemption I just cant get it I keep on getting infinite loops, have something wrong with my code, or the hero just stands there
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:
if friend.health < leastHealth and friend.type != "archer":
leastHealth = weakestFriend
weakestFriend = friend
friendIndex += 1
# Tell the weakest friends to go home first.
if weakestFriend:
hero.say('Hey ' + weakestFriend.id + ', go home!')
You’ve set friendIndex at 0 to start, and there are 4 friends. Will this ever be true?
Also this line:
friendIndex += 1
needs to run every time the ‘while friendIndex’ loop runs. At the moment it only runs if both the if statements are true. What do you change to make this happen?
I have tried everything you guys said to do but a villager just dies on the sixth line, it gets stuck on defining the friends and the weakest villager dies
while True:
weakestFriend = None
leastHealth = 9999
friendIndex = 0
# Find which friend has the lowest health.
friends = hero.findFriends()
while friendIndex < len(friends):
friend = (friendIndex)
if friend:
if friend.health < leastHealth and friend.type != "archer":
if friend.Health < leastHealth:
leastHealth = friend.health
friendIndex += 1
# Tell the weakest friends to go home first.
if weakestFriend:
hero.say("Hey " + weakestFriend.id + ", go home!")