Im just learning Python now and trying to do the tic tac toe game by myself. I have written this code, but I do not know what's wrong with my logic. def player_choice(board): #this function asks for the players next position
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
As opposed to this one, which is deemed correct: 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
input returns a string. In the second code you are converting to integer, so it is ok.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.