在python2,/
只留下了整数部分,去掉了小数,是int型。而在python3里,/
的结果是真正意义上的除法,结果是float型。所以便出现了Error Message: ‘float’ object cannot be interpreted as an integer。
In:
for i in range(r / M):
解决方法:也即把/改为//即可
You're creating a float as a result - to fix this use the int division operator:
for i in range(r // M):