Doing so will increase the readability and make it easier to splice in new logic. If this is a learning exercise for you I would recommend refactoring your code to find a way wrap all your logic blocks into functions and getting everything to flow without the use of sys.exit(). Put a call to is_tie() directly after both while loops like this. Here's the function that does what you want. # Checks for empty spot and places an 'O' if it exists, otherwise Player_b = int(raw_input('Player B, please select a spot that is \ # program will terminate so it does not ask for player A input after. # the conditions as to whether or not player B wins. # While loop to ask for player B input and display the board as well as check # Checks for empty spot and places an 'X' if it exists, otherwise Player_a = int(raw_input('Player A, please select a spot that is not taken \ # the program will terminate so it does not ask for player B input after. # check conditions to see whether or not player A wins. # Initial while loop will ask for player A input and show the board as well # Function used to automate process for checking every possible way to win If board = char and board = char and board = char: # Define and create tic tac toe gameboard Does it have to be within the while loop or does it require it's own separate function? import sys However, if the program ends in a draw, it will keep requesting user input. If Player A or Player B ever wins, it is announced and the program terminates. Need help coding how to tell player if game is a tie.I have this Python program that plays tic tac toe between two human players. not sure how to to tell players it is a tie. Same tic tac toe game from earlier for my school, I forgot to figure in if the game is a draw.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |