Issue
I'm trying to stop my program when the Warrior are Priest are both with 0 or < 0 or the vampire goes to 0 our < 0 if not they will not advance for the next round and just finish the battle that way, and set up a winner.
while (warrior[0] and priest[0]) > 0 or vampire[0] > 0: #Loop until all of the group die or the enemy dies
first_turn() #Execute the first turn
if (warrior[0] and priest[0]) > 0 or vampire[0] > 0:
second_turn() #Execute the second turn
if (warrior[0] and priest[0]) > 0 or vampire[0] > 0:
third_turn() #Execute the third turn
if (warrior[0] and priest[0]) > 0 or vampire[0] > 0:
initiative_phase()
else:
break
I've tried the way it is above, but I'm not catching why is it not stopping.
Solution
Change the while condition to:
while (warrior[0] > 0 or priest[0] > 0) and vampire[0] > 0:
We added parenthesis Because precedence of logical 'and' is greater than the logical 'or'. If warrior[0]>0 is true it does not consider whether vampire[0]>0 condition at all.
Answered By - Kedar U Shet
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.