0
tic_row1=[7,8,9]
tic_row2=[4,5,6]
tic_row3=[1,2,3]

# Display the grid
def grid_display():
    print(tic_row1)
    print(tic_row2)
    print(tic_row3)

def choice_check():
    
   
    #Choose a plot
    plot='pick'
    number_range= range(0,10)
    number_check=False

    while plot.isdigit()==False or number_check==False:
        plot=input('Please pick a plot number (1-9): ')

        if plot.isdigit()==False:
            plot=input("That isn't a number!")
        if plot.isdigit()==True:
            if int(plot) in number_range:
                number_check=True
            else:
                print("The number must be from (1-9)!")
                number_check=False
    return int(plot)



def game_initiate():
    plot=choice_check()
    team='cookie'
    index=None
    while team != 'x' or 'o':
        team=input("Choose 'X' or 'O': ")

        if team.islower() == 'x' or 'o':
            if plot in range(7,10):
                index=tic_row1.index(plot)
                tic_row1[index]=team
                return tic_row1
            elif plot in range(4,7):
                index=tic_row2.index(plot)
                tic_row2[index]=team
                return tic_row2
            if plot in range(1,4):
                index=tic_row3.index(plot)
                tic_row3[index]=team
                return tic_row3

def game_order():
    nums=range(1,10)
    while nums in tic_row1 or tic_row2 or tic_row3:
        grid_display()
        choice_check()
        game_initiate()

game_order()

So I made this tic-tac-toe game and ultimately it works. For some reason, it asks the sentence 'Please pick a plot number (1-9):' twice. The problem would be in the 'choice_check' function, the second function under the print grids. Maybe I'm just blind, but I can't think of why it's doing this. Everything looks good to my beginner eyes.

Iron Lemon
  • 19
  • 8

2 Answers2

1

For those that want to copy the fixed version. Thanks again to the ones that highlighted what I over-read and missed many times.

tic_row1=[7,8,9]
tic_row2=[4,5,6]
tic_row3=[1,2,3]

# Display the grid
def grid_display():
    print(tic_row1)
    print(tic_row2)
    print(tic_row3)

def choice_check():
    
   
    #Choose a plot
    plot='pick'
    number_range= range(0,10)
    number_check=False

    while plot.isdigit()==False or number_check==False:
        plot=input('Please pick a plot number (1-9): ')

        if plot.isdigit()==False:
            plot=input("That isn't a number!")
        if plot.isdigit()==True:
            if int(plot) in number_range:
                number_check=True
            else:
                print("The number must be from (1-9)!")
                number_check=False
    return int(plot)



def game_initiate():
    plot=choice_check()
    team='cookie'
    index=None
    while team != 'x' or team != 'o':
        team=input("Choose 'X' or 'O': ")

        if team.islower() in {'x','o'}:
            if plot in range(7,10):
                index=tic_row1.index(plot)
                tic_row1[index]=team
                return tic_row1
            elif plot in range(4,7):
                index=tic_row2.index(plot)
                tic_row2[index]=team
                return tic_row2
            if plot in range(1,4):
                index=tic_row3.index(plot)
                tic_row3[index]=team
                return tic_row3

def game_order():
    nums=range(1,10)
    while nums in tic_row1 or tic_row2 or tic_row3:
        grid_display()
        game_initiate()

game_order()
Iron Lemon
  • 19
  • 8
  • hi, This `while team != 'x' or 'y':` will result in an infinite loop. Please see [this](https://stackoverflow.com/questions/20002503/why-does-a-x-or-y-or-z-always-evaluate-to-true/20002504#20002504) answer for your `value == "x" or "y"`-like comparisons. Past that, there is also the "DeMorgan" issue: `while team != "x" or team != "y"` will still give infinite loop even though the first issue is fixed. Whatever value you give to `team`, that condition is *always* true; can you tell why? – Mustafa Aydın May 18 '21 at 08:30
1

Remove "choice_check()" from game_order() method, as below:

def game_order():
    nums=range(1,10)
    while nums in tic_row1 or tic_row2 or tic_row3:
        grid_display()
        game_initiate()