Printing out works, but response said it didn't


#1



https://www.codecademy.com/courses/python-beginner-en-IZ9Ra/0/1?curriculum_id=4f89dab3d788890003000096


my code works, but when I press "save&submit code" it says "it looks like your code did not print 'Adam'". But it does print all of the names, including Adam.


I expect to get to the next task


names = ["Adam","Alex","Mariah","Martine","Columbus"]
for names in [names]:
    print names


#2

Hi @anlena,
You have to print the items of your names list.
to do this we use for loop.

suppose x is a list of numbers and I want to print the items (i.e 1,2,3,4,5) of this list..

x = [1 ,2 ,3 ,4 ,5]

we use this syntax..

for iteration_variable in list_name:
    print iteration_variable

so I have to iterate over list x, I'd do this..

for i in x:
    print i

You can use any name for iteration_variable (I named it i ,Iteration variable name follows variable name-rule of python)
if you look at the example i did not put x inside [...] right?
also you should not use same list name as iteration variable..

like..

for x in x:
    print x

It will not throw an error but it will confuse you.
i hope it clears your doubt.

also..
Read the theory and instructions again.
You can also read this thread for more clarification.


#3

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