Access by index


#1

Here is my code that isn't working.

numbers = [5, 6, 7, 8]

print "Adding the numbers at indices 0 and 2..."
print numbers[0] + numbers[2]
print "Adding the numbers at indices 1 and 3..."
print numbers[1+3]

The error that comes up says...
Adding the numbers at indices 0 and 2...
12

Adding the numbers at indices 1 and 3...

Traceback (most recent call last):
  File "python", line 6, in <module>
IndexError: list index out of range

Please help!


#2

This is pollling numbers[4] which does not exist. Following the code given in the first example,

print numbers[1] + numbers[3]

#3

I did numbers [1] + number [3] but got an error.

Yet I did numbers [3] + numbers [1] and it was the correct answer, what happened?!


#4

We generally write index without whitespace:

print numbers[1] + numbers[3]

Be sure to check your spelling.


#5

Good work ;3 i leik how you code, maybe u could teach me sometime
:heart_eyes:


#6