Search code examples
pythonjupyter-notebookinfinite-loop

endless loop in python / Jupyter Notebook stops working


Any idea why this code is creating an endless while loop? I wrote it following my instructor's tutorial, but after I try to call the function, my Jupyter Notebook becomes busy and stops executing all codes. After googling it, the most common explanation would be an endless while loop. Can someone help me figure it out?

def player_input():
    marker = ''

    while marker != 'X' and marker!='O':
        marker = input('Player 1, choose X or O: ')

    player1 = marker

    if player1 == 'X':
        player2 = 'O'
    else:
        player2 = 'X'

    return (player1,player2)

enter image description here


Solution

  • Your code is doing what it's supposed to do. The loop won't break until user provides input.

    You need to provide input here, Either X or O: You need to provide input here, Either X or O