Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics (2015) Logic in Python Loop

zaki azizi
zaki azizi
421 Points

how can I solve this problem ? please help me.

I can not solve this problem

loop.py
hellos = [
    "Hello",
    "Tungjatjeta",
    "Grüßgott",
    "Вiтаю",
    "dobrý den",
    "hyvää päivää",
    "你好",
    "早上好"
]
for words in hellos:
    print(hellos + [' World'])

2 Answers

Break the problem down into smaller steps.

So, before trying to print all the different ways you can print "Hello world" based on all the different strings that are part of the hellos list, try to print just one way without the loop

hellos = 'Hello'
print('{} World'.format(hellos))

{} is the placeholder that will be replaced by whatever you provide inside the format() method

Now, if you have to go through the list, you need to get one item in the list at a time so that your output looks as below: Hello World Tungjatjeta World Grüßgott World

and so on.

One way to do this is shown below where the for loop runs repeated with different values of hellos list assigned to word for word in hellos: print('{} World'.format(word))

Does that make sense?

zaki azizi
zaki azizi
421 Points

Thank you my Friend