Python NIM game: how do i add new game (y) or (n)
<p>I have a question: How do i put New Game in code or PlayAgain (y) or (n)
This is for my school project.  I have been trying to find myself a solution but it will only repeat question "play again" or error. </p>

<pre><code>    import random

    player1 = input("Enter your real name: ")
    player2 = "Computer"

    state = random.randint(12,15)
    print("The number of sticks is " , state)
    while(True):
        print(player1)
        while(True):
            move = int(input("Enter your move: "))
            if move in (1,2,3) and move &lt;= state:
                break
            print("Illegal move") 
        state = state - move
        print("The number of sticks is now " , state)
        if state == 0:
            print(player1 , "wins")
            break
        print(player2)
        move = random.randint(1,3)
        if state in (1,2,3):
            move = state
        print("My move is " , move)
        state = state - move
        print("The number of sticks is now " , state)
        if state == 0:
            print("Computer wins")
            break
</code></pre>

<p>Your loop condition is always <code>True</code>.  This is what needs adjusting. Instead you only want to loop while the user wants to continue</p>

<pre><code>choice = 'y'  # so that we run at least once
while choice == 'y':
    ...
    choice = input("Play again? (y/n):")
</code></pre>

<p>You will have to make sure to reset the state each time you begin a new game.</p>

<p>Since you have multiple points at which your game can end, you'll need to either refactor your code, or replace the <code>break</code>s. For example</p>

<pre><code>if state == 0:
    print(player1 , "wins")
    choice = input("Play again? (y/n):")
    continue
</code></pre>

<p>Or what may be easier is to put the game into an inner loop</p>

<pre><code>choice = 'y'
while choice == 'y':
  while True:
    ...
    if state == 0:
      print(player1, "wins")
      break
    ...
  choice = input("Play again? (y/n):")
</code></pre>

<p>At that point I'd start factoring things into functions if I were you</p>

python python-3.x