Python: How to end a while loop while it is running if the while condition changes during the loop?
问题 I need some help with code in a text based game I am trying to make. My game uses health, and the code starts off with "while health>0:", and in another point in the game, when health eventually =0, the loop still continues. How do I make the loop end when health=0, without finishing the whole loop. Here is an example: health=100 while health>0: print("You got attacked") health=0 print("test") Should the code not be stopping when health=0, and not print "test"? How to I get it to stop when