Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Basics (2015) Logic in Python Loop

loop

Hi, Im having a little trouble understanding the loop side of things ? WAtched the video a dozen times and must me over thinking the situation or missing something ? thank you

loop.py
hellos = [
    "Hello",
    "Tungjatjeta",
    "Grüßgott",
    "Вiтаю",
    "dobrý den",
    "hyvää päivää",
    "你好",
    "早上好"
]

for world in hellos:
    for world in list:
        print(world)

1 Answer

Umesh Ravji
Umesh Ravji
42,386 Points

Hi Jammie, you have the first part fine with looping over each item in the list, but then you have another for loop which isn't valid. I'd recommend naming the variable something more suitable, so I'm going to rename world to hello. Printing each of the items in the hellos list is simply done by:

for hello in hellos:
    print(hello)

Results in:

Hello
Tungjatjeta
Grüßgott
Вiтаю
dobrý den
hyvää päivää
你好
早上好

The question wants you to print out the following:

Hello World
Tungjatjeta World
Grüßgott World
Вiтаю World
dobrý den World
hyvää päivää World
你好 World
早上好 World

Change the part inside the loop so that it prints that instead of just the word in the list.

Hi Jammie,

It looks like you have the concept down, you just need to change the formatting a little bit so you get the desired output. Try this...

hellos = [
    "Hello",
    "Tungjatjeta",
    "Grüßgott",
    "Вiтаю",
    "dobrý den",
    "hyvää päivää",
    "你好",
    "早上好"
]

for hello in hellos:
        print("{} World".format(hello))