How do I ask the user if they want to play again and repeat the while loop?
<p>Running on Python, this is an example of my code: </p>

<pre><code>import random 

comp = random.choice([1,2,3])

while True:
     user = input("Please enter 1, 2, or 3: ")
     if user == comp
             print("Tie game!")
     elif (user == "1") and (comp == "2")
             print("You lose!")
             break
     else:
             print("Your choice is not valid.")
</code></pre>

<p>So this part works. However, how do I exit out of this loop because after entering a correct input it keeps asking "Please input 1,2,3".</p>

<p>I also want to ask if the player wants to play again:</p>

<p><strong>Psuedocode:</strong></p>

<pre><code>     play_again = input("If you'd like to play again, please type 'yes'")
     if play_again == "yes"
         start loop again
     else:
         exit program
</code></pre>

<p>Is this related to a nested loop somehow?</p>

<p>Points for your code:</p>

<ol>
<li>Code you have pasted don't have <code>':'</code> after <code>if,elif</code> and <code>else.</code></li>
<li>Whatever you want can be achived using Control Flow Statements like <code>continue and break</code>. <a href="https://docs.python.org/2/tutorial/controlflow.html" rel="nofollow">Please check here for more detail</a>.</li>
<li>You need to remove break from "YOU LOSE" since you want to ask user whether he wants to play.</li>
<li>Code you have written will never hit "Tie Game" since you are comparing string with integer. User input which is saved in variable will be string and <code>comp</code> which is output of random will be integer. You have convert user input to integer as <code>int(user)</code>.</li>
<li>Checking user input is valid or not can be simply check using <code>in</code> operator.</li>
</ol>

<p><strong>Code:</strong></p>

<pre><code>import random

while True:
     comp = random.choice([1,2,3])
     user = raw_input("Please enter 1, 2, or 3: ")
     if int(user) in [1,2,3]:
         if int(user) == comp:
            print("Tie game!")
         else:
            print("You lose!")
     else:
            print("Your choice is not valid.")

     play_again = raw_input("If you'd like to play again, please type 'yes'")
     if play_again == "yes":
        continue
     else:
         break
</code></pre>

python loops while-loop nested