部分python代码未运行/执行
我用jupyter笔记本写代码,当我运行每个代码块时 所有运行良好,没有任何问题,但整个程序运行正常 win_check函数不运行,该代码用于检查a玩家是否已获胜或棋盘是否已满,以便程序可以重置,但现在它只是跳转到replay函数。。有什么帮助吗部分python代码未运行/执行,python,Python,我用jupyter笔记本写代码,当我运行每个代码块时 所有运行良好,没有任何问题,但整个程序运行正常 win_check函数不运行,该代码用于检查a玩家是否已获胜或棋盘是否已满,以便程序可以重置,但现在它只是跳转到replay函数。。有什么帮助吗 关于我应该做什么请仔细查看问题中的代码,并花时间将其正确格式化。目前,您的所有代码都是win\u check函数的一部分,该函数在第一行有一个return。此外,行与行之间的缩进级别不同,并且有多个不必要的空行,导致不必要的滚动。您如何知道该函数没有运
关于我应该做什么请仔细查看问题中的代码,并花时间将其正确格式化。目前,您的所有代码都是
win\u check
函数的一部分,该函数在第一行有一个return
。此外,行与行之间的缩进级别不同,并且有多个不必要的空行,导致不必要的滚动。您如何知道该函数没有运行?尝试将print(“in win\u check”)
放在函数中。@Barmar是的,它没有运行,但其他所有东西都运行?它不断地问你选择,印刷电路板,等等。?它不可能跳过函数调用。您确实将print语句放在了return
语句之前,对吗?是的,我确实将print语句放在了return语句之前
def win_check(board,mark):
return ((board[7] == mark and board[8] == mark and board[9] == mark) or # across the top
(board[4] == mark and board[5] == mark and board[6] == mark) or # across the middley
(board[1] == mark and board[2] == mark and board[3] == mark) or # across the bottom
(board[7] == mark and board[4] == mark and board[1] == mark) or # down the middle
(board[8] == mark and board[5] == mark and board[2] == mark) or # down the middle
(board[9] == mark and board[6] == mark and board[3] == mark) or # down the right side
(board[7] == mark and board[5] == mark and board[3] == mark) or # diagonal
(board[9] == mark and board[5] == mark and board[1] == mark)) # diagonal
print('Welcome To Tic Tac Toe')
while True:
the_board =[' ']*10
player1_symbol, player2_symbol = player_symbol()
player_turn = play_first()
print(player_turn + 'Will go first')
Ready_to_play = input('Ready to play?, Yes or No')
print('ready to play running')
if Ready_to_play == 'Yes' or Ready_to_play == 'yes':
print('game on')
game_on = True
print('game on runs')
else:
game_on = False
while game_on :
if player_turn == 'Player 1':
print('am running player 1')
show_board(the_board)
print('am showing the board')
position = player_choice(the_board)
place_symbol(the_board, player1_symbol,position)
print('i added the marker')
show_board(the_board)
if win_check(the_board, player1_symbol): #this code is not executing
show_board(the_board)
print('check if there is a win')
print('Player 1 wins!!')
game_on = False
else:
if full_board_check(the_board): # this one also
show_board(the_board)
print('Tie game!!')
game_on = False
else:
player_turn = 'Player 2'
else:
print('am running player 2')
show_board(the_board)
print('showing the board')
position = player_choice(the_board)
place_symbol(the_board, player2_symbol,position)
print('adding the marker')
show_board(the_board)
if win_check(the_board, player2_symbol): # this code too not executing
show_board(the_board)
print('Player 2 wins!!')
game_on = False
else:
if full_board_check(the_board):
show_board(the_board)
print('Tie game!!')
game_on = False
else:
player_turn = 'Player 1 '
if not replay():
print('End of game')
break