“类型错误:range()期望整数结束参数,浮点数”甚至使用int()

时间:2015-11-28 20:05:22

标签: python python-2.7

这是完整的代码。令我困惑的是,我正在使用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.

0 个答案:

没有答案