这是完整的代码。令我困惑的是,我正在使用int将l / 2的上限变为整数,但它仍然不起作用。错误必须在代码中的其他地方,除非......我很好。感谢
def switcheroo(vec):
from math import ceil
from __future__ import division
l = len(vec) - 1
holdingcell = []
for i in range(int(ceil(l/2))):
holdingcell = vec[i]
vec[i] = vec[l-i+1]
vec[l-i+1] = holdingcell
return vec
我得到的错误是:
>>> o = switcheroo(v)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "switcheroo.py", line 8, in switcheroo
for i in range(int(ceil(l/2))):
TypeError: range() integer end argument expected, got float.