title: Python: How to use user input to close or continue a while loop
body: <p>I am new to python, and still trying to figure out the basics. I've looked for an answer online, but no solutions seem to work for me. I don't know if I'm missing something small, or my total structure is wrong. The calculation portion of my code works like it's supposed to.</p>
  
  <p>My problem is, I can't figure out how to ask the user to input yes or no resulting in:</p>
  
  <p>(the answer YES restarting the loop so the user can try another calculation)</p>
  
  <p>(the answer NO closing the loop/ending the program)</p>
  
  <p>Please let me know what you suggest!</p>
  
  <pre><code>    play = True
  
  while play:
  
      hours = float(input("Please enter the number of hours worked this week: "))
      rate = float(input("Please enter your hourly rate of pay: "))
  
      #if less than 40 hrs
      if hours &lt;= 40:
          pay = hours * rate
          print "Your pay for this week is",pay
  
      #overtime 54hrs or less   
      elif hours &gt; 40 &lt; 54:
          timeandhalf = rate * 1.5
          pay = (40 * hours * rate) + ((hours - 40) * timeandhalf)
          print "Your pay for this week is",pay 
  
      #doubletime more than 54hrs        
      elif hours &gt; 54:
          timeandhalf = rate * 1.5
          doubletime = rate * 2
          pay = (40 * hours * rate) + ((hours - 40) * timeandhalf) + ((hours - 54) * doubletime)
          print "Your pay for this week is",pay    
  
  
      answer = (input("Would you like to try again?: "))
      if str(answer) == 'yes':
          play = True
      else:
          play = False
  </code></pre>