May-07-2019, 03:00 PM
i am trying to use while loops and if statements to make a text based battle sim in python but i cant figure out how to use the while loops with multiple variables
when i go to run it it complains about how my else statements are invalid syntax but if i remove the else statements and try to run it the while loop doesn't include the second if then statement so its stuck being "tylers turn" also if i just get rid of the second turn and try to run it with the same while statement it doesn't end and wants both conditions to be met instead of just one of either one.
any way to fix this im also open for suggestion on how to make my code better
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
import random T = 10 H = 10 while H > 0 or T > 0 : print "its tylers turn" p2 = raw_input ( "use punch? " ) if p2 = = "yes" : punch2 = random.randint( 2 , 4 ) H = H - punch2 print "THE PUNCH LANDS! haydyns health is now" print (H) else : print ( "what!?!?!" ) if H = = H< 1 : print "-------------" print "TYLER WINS!!!" print "-------------" print "its haydyns turn" p = raw_input ( "use punch? " ) if p = = "yes" : punch1 = random.randint( 1 , 5 ) T = T - punch1 print "THE PUNCH LANDS! tylers health is now" print (T) else : print "what?!?!?" if T = = T< 1 : print "--------------" print "HAYDYN WINS!!!" print "--------------" |
any way to fix this im also open for suggestion on how to make my code better