vendredi 13 septembre 2019

TypeError: unsupported operand type(s) for -: 'str' and 'int' within an if statement

I'm trying to make a tic-tac-toe game. This code worked on Python 2, but doesn't on Python 3. I keep getting TypeError: unsupported operand type(s) for -: 'str' and 'int' for line 18.

Here is the code:

gameList = []
for i in range(9):
    gameList.append(' ')

while True:
    while True:
        x = input('Which square? ')
        if(gameList[x-1] == ' '):
            gameList[x-1] = 'X'
            printgame()
            break

        else:
            print('Choose an unchosen square.')
            continue

    while True:
        y = random.randint(0,8)
        if(gameList[y] == ' '):
             gameList[y] = 'O'
             printgame()
             break
        else:
             print('Choose an unchosen square.')
             continue

Aucun commentaire:

Enregistrer un commentaire