不可解决的类型:int()<名单()

时间:2013-10-12 17:51:53

标签: python-3.x

next_number = []

for i in range(len(fib)):

    while next_number < [10]:
        next_number = fib[i] + fib[i + 1]
        fib.append(next_number)

print(next_number)

Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module>
euler_fibbonacci([0, 1])
File "C:\Python33\euler_fibbonacci.py", line 17, in euler_fibbonacci
while next_number < limit:
TypeError: unorderable types: int() < list()

为什么他给我这个错误,因为next_number是list而[10]也是一个列表。

1 个答案:

答案 0 :(得分:2)

首先通过while循环执行此操作:

next_number = fib[i] + fib[i + 1]

fib[i] + fib[i + 1]int。下一个过程首先检查int是否小于[10],这会引发TypeError