首页 > 解决方案 > 如何修复不支持的操作数类型错误?

问题描述

我使用了一个 alpha beta 修剪代码,但它显示了这个错误

以下行中 +: 'int' 和 'str'" 的不支持的操作数类型: if (turn+num)%2==1:

这是本节的代码:

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')

我该怎么办?请帮忙

标签: python

解决方案


该错误表示未定义整数加字符串,因为加号对于字符串类型和 int 类型具有不同的含义。您可以这样更改输入行

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

推荐阅读