Python Guess game how to repeat
<p>I have been working on this guessing game but i just cant get it to repeat the game when the player says yes. The game gives you 5 attempts to guess the number that it thought of and then after it asks you if you would like to play again but when you say 'YES' it just keeps repeating the sentence and when you say 'NO' it does what its supposed to which is break the code</p>

<pre><code>def main():
    game = "your game"
    print(game)
    play_again()
import random #imports random number function
print("Welcome to the number guessing game!")
counter=1 #This means that the score is set to 0
number = int(random.randint(1,10))
while counter &gt;0 and counter &lt;=5:

    guess=int(input("Try and guess the number\n"))#tells the user to try and guess the number
    if guess!=number and guess&gt;number:
        print("wrong number! Try again you are too high")#tells you that you were wrong and that that you were too high
        counter=counter+1#adds 1 count for every attempt it took you to guess the number

    elif guess!=number and guess&lt;number:
        print("wrong number! Try again you are too low!")#tells you that you were wrong and tells you that you were too low
        counter=counter+1#adds 1 count for every attempt it took you to guess the number
    else:
        print("Well done! You have guessed the number i was thinking of! The number was ",number)#Prints this out when you guessed the number
        print("it took you ",counter, "attempts!")#tells you how many attempts it took you to guess the number

    if counter==2:
        print("4 attempts left before program ends")

    if counter==3:
        print("3 attempts left before program ends")

    if counter==4:
        print("2 attempts left before program ends")

    if counter==5:
        print("1 attempts left before program ends")

def play_again():
    while True:
        play_again = input("Would you like to play again?(yes or no) : ")
        if play_again == "yes":
            main()
        if play_again == "no":
            exit()
        else:
            print("I'm sorry I could not recognize what you entered")
main()
</code></pre>

<p>It's because your game code isn't in the function. Try it in this manner:</p>

<pre><code>&lt;import statements&gt;

def game():
    &lt;insert all game code&gt;

def main():
    while True:
        play_again = input("Would you like to play again?(yes or no) : ")
        if play_again == "yes":
            game()
        if play_again == "no":
            exit()
        else:
            print("I'm sorry I could not recognize what you entered")
</code></pre>

python helper python-3.5.2