![]() ![]() This is the quick fix: def next_turn(turn): In order for the later test if turn = human: to work correctly in all cases, the value of turn must be either X or O, not X or 0. There's one more problem in your code: def next_turn(turn): Then we go on to consider the ways to win. In addition, it makes sense to move the TIE check before the loop. We can make the function correct by reindenting return None so that it gets executed after the loop. That's unless the board is full, in which case you correctly return TIE, except you could have checked for a full board before trying to match any rows. Notice that return None is inside the loop, so you return None when the first row fails to match. Currently you have this: def winner(board): ![]() The function that checks for a win or tie is incorrect. Move = computer_move(board, computer, human)Ĭongrat_winner(the_winner, computer, human) for this is the best you will ever achieve.\n") Print("You were most lucky, human, and somehow managed to tie me. "But never again! I, the computer, so swears it\n!") ![]() Print("No, no! It cannot be! Somehow you tricked me, human. "Proof that computers are superior to humans in all regards.\n") ![]() Print("As I predicted, human, I am triumphant once more. # since no one ca win on next move, pick best open squareĭef congrat_winner(the_winner, computer, human): #make a copy to work with since function will be changing list. Choose another.\n")ĭef computer_move(board, computer, human): Print("\nThat square is already occupied, foolish human. Move = ask_number("Where will you move? (0 - 8): ", 0, NUM_SQUARES) Print("\nYour bravery will be your undoing. Go_first = ask_yes_no("Do you require the first move? (y/n): ") Will correspond to the board position as illustrated: You will make your move known by entering a number, 0 - 8. This will be a showdown between your human brain and my silicon processor. Welcome to the greatest intellectual challenge of all time: Tic-Tac-Toe. The program continues until all the spaces are mark with either "X" or "O". I have this code for Chapter 6 and when I ran the code and got the straight "X" in the board, it won't return the winner. I'm currently reading Michael Dawson's book Python for the Absolute Beginner. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |