Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

typeerror 'builtin_function_or_method' object has no attribute '__getitem__'

Here's the code:

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]

This code is supposed to make a Pascal's triangle. The error is on the sixth line.

like image 966
Roman Davis Avatar asked Oct 25 '12 19:10

Roman Davis


2 Answers

You need to change the brackets in The_End.insert[x + 1, y] to parenthesis.

The_End.insert(x + 1, y)

It's good practice in Python to use lowercase variable names. Uppercase is generaly used for classes.

like image 171
Nathan Villaescusa Avatar answered Nov 11 '22 11:11

Nathan Villaescusa


You need parenthesis instead of []:

The_End.insert(x + 1, y)
like image 17
Ashwini Chaudhary Avatar answered Nov 11 '22 10:11

Ashwini Chaudhary