Reputation: 128
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
Upvotes: 0
Views: 233
Reputation: 11155
just remove [
and ]
around names
variable i.e
for x in names:
that would print what you have asked for.
Upvotes: 2
Reputation: 599580
You're creating an extra list. You should just be doing:
for x in names:
Upvotes: 1
Reputation: 1121714
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.
Upvotes: 4