Bug with a program for a guessing game
<p>I am creating a program where a user had to guess a random number in a specific range and has 3 tries to do so. After each try, if the guess is correct you tell the user they won and if the guess is wrong you tell them its wrong and how many tries they have got remaining. When the number of tries exceed 3 without a correct guess, you tell the user they are out of tries and tell them they lost. When the program finishes after a correct or 3 wrong tries and the game is over, you ask if the user wants to play again. If they say "yes", you star the game again and if they say "no", you end the game.
This is the code I have come up with:</p>

<pre><code>import random
x =round(random.random()*5)
guess = False
tries = 0
while guess != True:
    if tries&lt;=3:
        inp = input("Guess the number: ")
        if tries&lt;3:
            if inp == x:
                guess = True
                print "Correct! You won"
            else:
                print "Wrong guess! Try again."
                tries = tries + 1
                print "Your remaining tries are",(3-tries)
        if tries&gt;2:
            if inp == x:
                guess = True
                print "Correct! You won"
            else:
                print "Wrong guess! You are out of tries"
                print "Game Over!"
again = raw_input("Do you want to play again? ")
if again == "no":
    print "Okay thanks for playing!"
elif again =="yes":
    print "Great!"
</code></pre>

<p>Now when you guess the correct number before 3 tries, the program seems to be working fine, but even when the number of wrong tries exceeds 3, the program keeps asking for more guesses but I want it to stop the program right there. The second thing I don't get is how do I start the whole game again when the user wants to play again? 
How can I modify my code to fix these errors?</p>

<p>You need to move where you set guess = True</p>

<pre><code>import random
x =round(random.random()*5)
guess = False
tries = 0
while guess != True:
    if tries&lt;=3:
        inp = input("Guess the number: ")
        if tries&lt;3:
            if inp == x:
                guess = True
                print "Correct! You won"
            else:
                print "Wrong guess! Try again."
                tries = tries + 1
                print "Your remaining tries are",(3-tries)
        if tries&gt;2:
            guess = True
            if inp == x:   
                print "Correct! You won"
            else:
                print "Wrong guess! You are out of tries"
                print "Game Over!"
again = raw_input("Do you want to play again? ")
if again == "no":
    print "Okay thanks for playing!"
elif again =="yes":
    print "Great!"
</code></pre>

<p>Before you were only ending on the condition where the last guess was correct. You should be ending whether the guess was correct or not.</p>

python python-2.7