Aug-15-2019, 04:37 PM
Please can someone help me out with my code I'm stuck with the validating part of my code which checks if the column selected is within the chosen size of my 2D array created on board_create()
My code keeps me stuck in a loop that just sends me back player 1 enter when I enter the correct input doesn't move onto player 2, can someone please fix this for me, thank you
My code keeps me stuck in a loop that just sends me back player 1 enter when I enter the correct input doesn't move onto player 2, can someone please fix this for me, thank you
turn = 0 invalid = True game_over = False def board_create(column, row): board = [[' '] * column for row in range(row)] return board def is_valid_location(column, column_choice, invalid, NO_of_spaces_left): if (column-1) < column_choice < (column+1): NO_of_spaces_left = NO_of_spaces_left - 1 invalid = False return column return column_choice return NO_of_spaces_left return invalid else: invalid = True return column return column_choice return NO_of_spaces_left return invalid row = int(input("How many rows: ")) column = int(input("How many columns: ")) NO_of_spaces_left = (row*column) board = board_create(column, row) while not game_over or NO_of_spaces_left != 0 : if turn == 0: while invalid == True: column = str(column) column_choice = int(input("Player 1 make your selection (1-"+column+"):")) column = int(column) is_valid_location(column, column_choice, invalid, NO_of_spaces_left) else: while invalid == True: column = str(column) column_choice = int(input("Player 2 make your selection (1-"+column+"):")) column = int(column) is_valid_location(column, column_choice, invalid, NO_of_spaces_left) turn = turn + 1 turn = turn % 2