11. Practice Makes Perfect


#1



https://www.codecademy.com/courses/python-beginner-en-KAgt5/2/5?curriculum_id=4f89dab3d788890003000096


I've checked this on other threads and its seems like the code should be right but it gives the error: "TypeError: list indices must be integers, not tuple" please help


to_21 = [x for x in range(1,22)]
print to_21

odds = to_21[::2]
print odds

middle_third = to_21[7,14]
print middle_third


#2

Read the error message that python is giving you, that includes a line number. Then consider what it is saying and compare that to the code.

"list indices" is plural of list index, so you're using an invalid value as an index for a list.

The error message is also very googleable


#3

Just use to_21 = range(1,22) and you would be fine.


#4

You Can Try This
to_21 = range(1,22)
odds=to_21[::+2]
print odds
middle_third = range(8,15)


#5

Ok i realized what happened, I used , instead of : in the last line

middle_third = to_21[7,14]

#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.