简体   繁体   中英

TypeError: unsupported operand type(s) for <<: 'int' and 'float'

There's this open source code I was trying out to play checkers, the code works just fine till the taking a piece part, and the following error appears:

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'

any help regarding how to fix this issue?

You can't shift bits by a float/decimal, the error is pretty clear. sum(...)/2 gives a float in the current operation.

What you can do, however, is perform an integer division using // , in Python 3. For Python 2, / does an integer division (for int operands) except you've overridden the default behavior.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM