Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我的project Euler代码抛出了不受支持的操作数类型错误,这有什么问题 number=[1,2] i=0 而我_Python_Math_Fibonacci - Fatal编程技术网

Python 我的project Euler代码抛出了不受支持的操作数类型错误,这有什么问题 number=[1,2] i=0 而我

Python 我的project Euler代码抛出了不受支持的操作数类型错误,这有什么问题 number=[1,2] i=0 而我,python,math,fibonacci,Python,Math,Fibonacci,错误显示: numbers = [1, 2] i = 0 while i < 4000000: x = int(len(numbers - 1)) new = numbers[x] + numbers[x-1] if new % 2 == 0: numbers.append(new) i = new print sum(numbers) - 1 回溯(最近一次呼叫最后一次): 文件“python”,第4行,在 TypeError:-:“list”和

错误显示:

numbers = [1, 2]
i = 0
while i < 4000000:
    x = int(len(numbers - 1))
    new = numbers[x] + numbers[x-1]
    if new % 2 == 0:
    numbers.append(new)
    i = new
print sum(numbers) - 1
回溯(最近一次呼叫最后一次):
文件“python”,第4行,在
TypeError:-:“list”和“int”的操作数类型不受支持

数字是一个数组,不能从数组中减去整数。你可能想要

Traceback (most recent call last):
  File "python", line 4, in <module>
TypeError: unsupported operand type(s) for -: 'list' and 'int'

大括号可能位于错误的位置:int(len(numbers)-1)如果您使用编程语言标记,则潜在的回答者可以更容易地找到与回答相关的问题。len(numbers)给出了列表的长度。但是len(数字-1)无效。
x = int(len(numbers) - 1)