1
numberOfArray1 = [1, 2, 5, 3]
numberOfArray2 = [4, 1, 3, 2]

allNumber = []

for array1 in numberOfArray1:
    for array2 in numberOfArray2:
        for i in numberOfArray1:
            for j in numberOfArray2:
                addedNumber = array1[i] + array2[j]
                allNumber.append(addedNumber)

print allNumber
4
  • 1
    Why are you looping at 4 levels? array1 is already a number, so you are essentially doing 1[i] + 1[j]. Commented Feb 22, 2015 at 0:15
  • Please post the full traceback. Commented Feb 22, 2015 at 0:16
  • 1
    You need to read the question guide. Commented Feb 22, 2015 at 0:47
  • Why don't you accept an answer? Click the checkmark below any answer's vote signs. Commented Jul 20, 2016 at 0:05

2 Answers 2

3

This line

for array1 in numberOfArray1:

iterates array1 through values of 1, 2, 5, and 3. Your reference to it later

addedNumber = array1[i] + array2[j]

is trying to treat array1 as an array; but it isn't. It's an integer, and cannot be subscripted like that. That's what 'int has no attribute getitem' means.

Sign up to request clarification or add additional context in comments.

Comments

0

So do like that:

n1 = [1, 2, 5, 3]
n2 = [4, 1, 3, 2]
n = []
for i in range(0, len(n1)):
    n.append(n1[i] + n2[i])
print n

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.