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

Maryan Tuzyak
Maryan Tuzyak
1,495 Points

python for loop , looping through all greetings and adding world to list

I need you to write a for loop that goes through each of the words in hellos and prints each word plus the word "World". So, for example, the first iteration would print "Hello World". this is the question asked in challenge and on preview i added 'hello world' but it says it cant find tungjatjeta when it's actually there

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

hellos.append("Hello World")

for hello in hellos:
    print(hello)

I don't think you need to append or remove anything from the list. You just need to iterate through the list printing each item in the list with a space and formatting it with "world". I can give you the code if I need to but just try doing it with what I gave you first.

Maryan Tuzyak
Maryan Tuzyak
1,495 Points

yea but this gets hello world in there but it doesn't read it at the end of the list for some reason. what code did you use to format it ?

7 Answers

My internet is poor where I'm located right now so I can't run the code so I'm going to tell you what I think it is:

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

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

I just ran the code I gave you and it passed the challenge.

hellos = [
    "Hello",
    "Tungjatjeta",
    "Grüßgott",
    "Вiтаю",
    "dobrý den",
    "hyvää päivää",
    "你好",
    "早上好"
]
# REMOVE THIS ---> hellos.remove("Hello")

# REMOVE THIS --->hellos.append("Hello World")

for hello in hellos:
    print("{} World".format(hello)) #Changed this line
Thomas Souza
Thomas Souza
7,943 Points

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

I answered in the comment.

Maryan Tuzyak
Maryan Tuzyak
1,495 Points

hellos = ["Hello{}","Tungjatjeta","Grüßgott","Вiтаю","dobrý den","hyvää päivää","你好","早上好"] hellos.format('world') for i in range(1): print(hellos)

Maryan Tuzyak
Maryan Tuzyak
1,495 Points

this printed out hello world 10 times, i'm still trying to figure it out thanks for the try

Maryan Tuzyak
Maryan Tuzyak
1,495 Points

thanks a lot bro, it worked i guess the spacing must of been off when i was putting it in.