Hareem Kapadia
Hareem Kapadia

Reputation: 21

How To Fix Unsupported Operand Type Error?

I used an alpha beta pruning code but it shows this error

unsupported operand type(s) for +: 'int' and 'str'" in the following line: if (turn+num)%2==1:

This is the code for this section:

def main():
num=input('enter player num (1st or 2nd) ')
value=0
global board
for turn in range(0,rows*cols):
    if (turn+num)%2==1: #make the player go first, and make the user player as 'X'
        r,c=[int(x) for x in input('Enter your move ').split(' ')]

        board[r-1,c-1]=1
        printBoard()
        value=checkGameOver(board)
        if value==1:
            print ('U win.Game Over')
            sys.exit()
        print ('\n')

What do I do? Please help

Upvotes: 2

Views: 38

Answers (1)

Feelx234
Feelx234

Reputation: 330

The error says that integer plus string is not defined because plus has different meanings for the string type and the int type. You could change the input line as such

num=input('enter player num (1st or 2nd) ') # num is a string
num=int(input('enter player num (1st or 2nd) ')) # num is a int

Upvotes: 1

Related Questions