代码如下:
The_Start = [1,1]
The_End = [1, 1]
for z in range(20):
for x in range(len(The_Start) - 1):
y = The_Start[x] + The_Start[x + 1]
The_End.insert[x + 1, y]
print The_End
The_Start = The_End
The_End = [1, 1]
这段代码应该是一个帕斯卡三角形。错误在第六行。
最佳答案
您需要将 The_End.insert[x + 1, y]
中的括号改为括号。
The_End.insert(x + 1, y)
在 Python 中使用小写变量名是一种很好的做法。大写通常用于类。
关于python - typeerror 'builtin_function_or_method' 对象没有属性 '__getitem__',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13075632/