0

I'm trying to make this code print out the names. However, CodeAcademy says that it is wrong perhaps it because I have "" around the names around them when they are printed. What I wonder is how do I print out each name line by line. I'm thinking I need to use len.

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

3 Answers 3

4

You are almost there; don't make names a nested list:

for x in names:
    print x

You are nesting the names list; you put it inside another list, which then has just one element. Looping over that will run once, and print the whole list object.

In other words, names is already a list, and the for statement will loop over it directly without any extra list syntax.

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

1 Comment

Attention to detail. The devil is in the detail when it comes to programming :0
2

just remove [ and ] around names variable i.e

for x in names:

that would print what you have asked for.

4 Comments

Thanks, I tried that...CodeAcademy didn't accept that. I"m going to see if I can make it print names line by line.
@RobB.: CodeAcademy has known problems and errors. Do check their forums if you run into strange inconsistent errors, and try things out in a Python interpreter. It is really easy to install your own.
@MartijnPieters English is not my mother tongue.I hope around indicates that be in for loop.Please correct me if i am wrong.
Much better; examples make it all the much clearer what you are talking about.
1

You're creating an extra list. You should just be doing:

for x in names:

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.