具有编码经验,但对python还是陌生的,他试图使用python制作井字游戏。 到目前为止,我还不知道如何在Jupyter Notebook中进行调试。因此,需要一些帮助以了解我在这里做错了什么。
下面是我的代码:
while game_on:
player1 = input('Enter the choice for player1(X/O):')
if player1.upper() == 'X':
print("Player 1 will go first and choice made is 'X'")
player1_turn = True
player2 = 'O'
else:
print("Player 1 will go first and choice made is 'O'")
player1_turn = True
player2 = 'X'
while player1_turn:
display_board(board)
position = int(input("player1: Enter the position where you want to place an 'X' or 'O'(1-9):"))
board[position] = player1.upper()
list1.append(position)
player1_turn = False
player2_turn = True
player_win = win(board)
if player_win:
display_board(board)
player1_turn = False
player2_turn = False
game_st = input('Would you like to play another game(y/n):')
if game_st.upper() == 'Y':
game_on = True
else:
game_on = False
break
else:
display_board(board)
position = int(input("Player2: Enter the position where you want to place an 'X' or 'O' (1-9):"))
board[position] = player2.upper()
list1.append(position)
player1_turn = True
player2_turn = False
当我执行我的代码并且控件进入第二条语句(以粗体显示)之后的内部while循环的“ else”部分时,控件将转到外部while循环(以标记为in)的第一条语句粗体),尽管它应该返回并返回内部while循环以再次使玩家1转向。
请指导和帮助理解。 非常感谢 MK