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

Greg Isaacson
PLUS
Greg Isaacson
Courses Plus Student 702 Points

Why is my code failing?

Hi guys!:)

I think my code is right but its not passing? any ideas??

Thanks:)

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

1 Answer

Umesh Ravji
Umesh Ravji
42,386 Points

Hi Greg, there are a few small issues with your code :)

1. Make sure to include the space between the hello and World by adding it to the front of str1.

2. Remove the while loop, it's not required in this case.

3. Make sure to use the value of hello (string item) for each iteration, not hellos (which is the list that you are iterating through.

str1 = " World"
for hello in hellos:
    print(hello + str1)
Greg Isaacson
Greg Isaacson
Courses Plus Student 702 Points

Hi Umesh,

Thank you for your detailed answer.

I did what you suggested and passed the test. I understand your reasons 1 & 2. I am not sure if I understand reason no 3.

Does the challenge ask me to print each word in the list + hello OR Hello world = to the number of words in hellos???.

I think that is what was confusing me!

Thanks!:)

Umesh Ravji
Umesh Ravji
42,386 Points

The question wants you to print each word in the list + World. Below is what the output should look like:

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