title: How do I properly code this subtraction loop? - EDIT: Solution found
body: <p>EDIT: New code added below the original code after I figured it out. </p>
  
  <p>ORIGINAL QUESTION: I'm new to the forum and am 2 days deep into learning python. </p>
  
  <p>Can someone tell me how to make this code loop until the orc is dead?</p>
  
  <p>It works as far as subtracting hit points but what is the proper logic for looping the combat part until OrcnewHP  &lt;= 0 to then print a victory text? </p>
  
  <p>UserHP is kind of useless at the moment but once I understand the loop I will have the orc attacking back. </p>
  
  <p>Also any tips on making sure the input (1) is pressed vs. any input would be appreciated but not needed. Just wrapping my head around the language and trying to make my own stuff as I trudge through my instruction book. This particular problem seems to have fallen through the cracks.</p>
  
  <hr>
  
  <pre><code># Combat Simulator
  
  import random
  import time
  
      print(' Welcome to combat simulator. Press any key then &lt;enter&gt; to begin.')
  input()
  
  print('loading...')
  time.sleep(2)
  
  UserHP=50
  UserHP=int(UserHP) 
  OrcHP=30
  OrcHP=int(OrcHP)
  
  print('An Orc stands before you. Press 1 to attack it.')
  input()
  
  OrcHP=str(OrcHP)
  print('The Orc has ' + OrcHP + 'hit points.')
  time.sleep(1)
  
  AttackValue = random.randint(1, 10)
  HitValue = AttackValue
  
  HitValue = str(AttackValue)
  
  print('You attack the Orc for ' + HitValue + ' hit points!')
  
  HitValue = int(HitValue)
  OrcHP=int(OrcHP)
  
  OrcnewHP = OrcHP - HitValue
  
  OrcnewHP = str(OrcnewHP)
  
  print('The orc has ' + OrcnewHP + ' hit points remaning.')
  time.sleep(1)
  </code></pre>
  
  <hr>
  
  <p>Up to this point it gives a value but I want to store that value and repeat a loop until the value reaches 0 or below with each input lowering it more and more.</p>
  
  <p>I would look for the answer more online but I don't know the name of what to look for or I'm sure it would be easy to find. </p>
  
  <p>Thanks in advance I know someone can probably code this in 20 seconds.. </p>
  
  <p>edit: Let me be more specific as I am new here and still looking around for an answer. I've noticed how particular everyone wants you to be about your questions so here goes:</p>
  
  <p>In this code the user presses anything and the program calls a random integer then subtracts that integer from the OrcHP to get OrcnewHP. </p>
  
  <p>I can only get this to occur once. I've tried indention to make a block of code but instead of repeating Python just says " unexpected indention." So apparently I'm so new I don't understand what python accepts as a "block" and what it does not. I'm basically trying to repeat from the line "AttackValue = random.randint(1, 10) to the line " print('The orc has ' + OrcnewHP + ' hit points remaning.') " Towards the end. During that time if the value of OrcnewHP reaches zero or below I want the code to print a victory text. Something like "print(' SMASH! The Orc is dead, good job!') </p>
  
  <p>It's a very simple loop with a break when the OrcnewHP reaches a value of zero or below to print the victory text. </p>
  
  <p>Again sorry for my noobness. If this question is just too simple for everyone to handle don't bother commenting. I will figure it out eventually but this seemed like a great place to ask questions and have people answer at their own CONVENIENCE.</p>
  
  <p>Thank you! </p>
  
  <p>Final Edit and ANSWER: I figured it out. Here is the new code in case anyone wants to know how to do this simple loop using a for loop for attempts.   </p>
  
  <hr>
  
  <pre><code># Combat Simulator
  
  import random
  import time
  
  print(' Welcome to combat simulator. Press any key then &lt;enter&gt; to begin.')
  input()
  
  print('loading...')
  time.sleep(2)
  
  UserHP=50
  UserHP=int(UserHP) 
  OrcnewHP=30
  OrcnewHP=int(OrcnewHP)
  Attempt=20
  
  print('An Orc stands before you. Press 1 to attack it.')
  input()
  
  OrcnewHP=str(OrcnewHP)
  print('The Orc has ' + OrcnewHP + 'hit points.')
  time.sleep(1)
  
  for attempt in range(20):
      AttackValue = random.randint(1, 10)
      HitValue = AttackValue
  
      HitValue = str(AttackValue)
  
      print('You attack the Orc for ' + HitValue + ' hit points!')
  
      HitValue = int(HitValue)
      OrcnewHP=int(OrcnewHP)
  
      OrcnewHP = OrcnewHP - HitValue
  
      OrcnewHP = str(OrcnewHP)
  
      print('The orc has ' + OrcnewHP + ' hit points remaning.')
      time.sleep(1)
  
      OrcnewHP = int(OrcnewHP)
  
      if OrcnewHP &gt; 0:
          print('Attack again? Press Y. ')
          input()
  
      if OrcnewHP &lt;= 0:
          break
  
  print('SMASH! Good job you destroyed the orc!')
  </code></pre>
  
  <hr>