# Mad max strikes back problem(python)

#1

could any one tell me what went wrong with my code

``````# The smaller ogres here do more damage!
# Attack the ogres with the least health first.
while True:
weakest = None
leastHealth = 99999
enemyIndex = 0
enemies = hero.findEnemies()

# Loop through all enemies.
while enemyIndex < len(enemies):
# If an enemy's health is less than leastHealth,
enemy = enemies[enemyIndex]
if enemy.health < leastHealth:
# make it the weakest and set leastHealth to its health.
enemy = weakest
enemy.health = leastHealth
if weakest:
# Attack the weakest ogre.
hero.attack(weakest)
pass
``````

enemy.health = leastHealth, the system say this code that "Type Error: can’t write property of non=object type:health.

many thx…

#2
``````enemy.health = leastHealth
``````

reverse

#3

done it but cannot solve the problem TT

#4
``````enemy = weakest
``````

Reverse

#5

Yes, Try: weakest = enemy

#6

solved, thx all, but y it will be different if I reverse it?
what is the different between
weakest = enemy and
enemy = weakest
in coding?

#7

weakest = 11
enemy = 44
weakest = enemy
weakest = 44
enemy = 44

weakest = 11
enemy = 44
enemy = weakest
weakest = 11
enemy = 11

#8

@Sui_Shing_Lung

Lets assume enemy = Ogre & Weakest = Munchkin

You are saying that Munchkin’s NEW VALUE is Ogre.

But if you reverse it, you are saying Ogre’s NEW VALUE is Munchkin.

Thus, you end up with different results.

#9

thx all , i got it , u all r so kind!!