我不知道这段代码有什么问题

时间:2021-01-20 16:59:12

标签: python

我现在只是在学习 Python 并尝试自己做 tic tac toe 游戏。我写了这段代码,但我不知道我的逻辑有什么问题。 def player_choice(board): #这个函数询问玩家下一个位置

i= 0

if full_board_check(board):
    print ("All the positions have been filled, the game is over")
    
while i not in [1,2,3,4,5,6,7,8,9] or board[i]=='X' or board[i]=='Y':  
     i=input('Please choose a number')
                     
        
        
return i       
   

与这个相反,它被认为是正确的: def player_choice(board):

position = 0

while poistion not in [1,2,3,4,5,6,7,8,9] or not space_check(board,position):
    position=int(input("Please choose a valid position"))
    
    
return position
     

1 个答案:

答案 0 :(得分:0)

输入返回一个字符串。在第二个代码中,您要转换为整数,所以没问题。