python - 如何修复不支持的操作数类型错误?
问题描述
我使用了一个 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')
我该怎么办?请帮忙
解决方案
该错误表示未定义整数加字符串,因为加号对于字符串类型和 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
推荐阅读
- ionic-framework - 我可以在 CapacitorJS 应用程序中使用 AdSense 在所有 3 个平台上展示广告:Web、iOS 和 Android?
- amazon-web-services - 如何在运行 nginx 和 jenkins 的 AWS ec2 Ubuntu 实例上释放空间?
- r - R - Cluster <- parallel::makeCluster(type='PSOCK', spec=spec) - 崩溃的窗口
- python - 在列中字典内的值上删除数据帧上的重复项
- visual-studio-code - Visual Studio Code JSON 设置
- javascript - 模板文字中的 JavaScript 换行编码
- python-3.x - Python ctypes EnumThreadWindows 失败并出现错误 87 (ERROR_INVALID_PARAMETER)
- sql - HiveQL 如何将十进制格式的毫秒转换为 mm:ss.SSS
- node.js - Docker 和节点:致命错误:达到堆限制分配失败 - JavaScript 堆内存不足
- javascript - PHP函数输出仅在点击页面后更新