这个开源代码我试图玩跳棋,代码工作得很好,直到拍了一块,然后出现以下错误:
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'
有关如何解决此问题的任何帮助?
答案 0 :(得分:3)
您不能通过浮点/小数移位位,错误很明显。 sum(...)/2
在当前操作中给出一个浮点数。
然而,你可以做的是在Python 3中使用//
执行整数除法。对于Python 2,/
执行整数除法(对于int操作数),除非你重写了默认行为。