Stuck on This intro python exercise


#1

Hello
Exercise goal: Practice using for loops.

We have some new hires at work, and their names are in the list names.

Instructions
Your job:

Use a for loop to print "Hello " for every name in the list.

For example, the first line of output should be:

Hello Adam

What I have:

names = ['Adam', 'Tanya', 'Alice', 'Sean']
for Adam in names:
    print "Hello Adam"
for Tanya in names:
    print "Hello Tanya"
for Alice in names:
    print "Hello Alice"
for Sean in names:
    print "Hello Sean"

But it prints everything 4 times


#2

You have four for loops, so everything gets printed for times. lets look at this code:

items = ['one','two','three','four']
for item in items:
   print item

the for loop assign the values in the list to item (in turn), and then you can print them. You only need only one loop. Otherwise a loop would be kind of pointless


#3

Thank! I appreciate your quick response.

I understand what you are saying about having 4 loops. it does seem kinda pointless :stuck_out_tongue: