lundi 2 décembre 2019

I dont understand whats wrong with my if statement. Ive tried many things but nothing changes. Can someone look over it and help me out?

Ive created an if statement for an assignment where we must create a video game. In this game, i want to print a message when a players health equals 0 and to remove the player from a list using the pop method. For some reason my if statements dont work and the health goes into negatives.

heres the part of my game where the if statements are:

  while player_1["Health"] > 0 or player_2["Health"] > 0 or player_3["Health"] > 0 or player_4["Health"] > 0 or player_5["Health"] > 0:
attack(random.choice(player_lst))
if player_1["Health"] <= 0:
  print(player_1["name"], "has died")
  player_lst.pop(0)
elif player_2["Health"] <= 0:
  print(player_2["name"], "has died")
  player_lst.pop(2)
elif player_3["Health"] <= 0:
  print(player_3["name"], "has died")
  player_lst.pop(2)
elif player_4["Health"] <= 0:
  print(player_4["name"], "has died")
  player_lst.pop(3)
elif player_5["Health"] <= 0:
  print(player_5["name"], "has died")
  player_lst.pop(4)

even if i make the indentation so that it is outside the while loop, it doesnt work.

Aucun commentaire:

Enregistrer un commentaire