TypeError: unsupported operand type(s) for <<: 'int' and 'float'
TypeError: unsupported operand type(s) for <<: 'int' and 'float'
有这个开源代码我正在尝试玩西洋跳棋,代码工作正常,直到参与其中,出现以下错误:
line 73, in make_move
taken_piece = int(1 << sum(i for (i, b) in enumerate(bin(move)[::-1]) if b == '1')/2)
TypeError: unsupported operand type(s) for <<: 'int' and 'float'
关于如何解决这个问题的任何帮助?
您不能将位移动 float/decimal,错误很明显。 sum(...)/2
在当前操作中给出一个浮点数。
但是,您可以在 Python 3 中使用 //
执行整数除法。对于 Python 2,/
执行整数除法 (对于 int 操作数),除非您覆盖了默认行为。
有这个开源代码我正在尝试玩西洋跳棋,代码工作正常,直到参与其中,出现以下错误:
line 73, in make_move
taken_piece = int(1 << sum(i for (i, b) in enumerate(bin(move)[::-1]) if b == '1')/2)
TypeError: unsupported operand type(s) for <<: 'int' and 'float'
关于如何解决这个问题的任何帮助?
您不能将位移动 float/decimal,错误很明显。 sum(...)/2
在当前操作中给出一个浮点数。
但是,您可以在 Python 3 中使用 //
执行整数除法。对于 Python 2,/
执行整数除法 (对于 int 操作数),除非您覆盖了默认行为。