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 Sequences Sequence Iteration Iterating With For Loops

Bobur Azimov
Bobur Azimov
2,547 Points

Write a for loop that iterates over the provided list. The body of the for loop should print

Challenge Task 1 of 2

Write a for loop that iterates over the provided list. The body of the for loop should print the current element in the list. I dont know what to do ...

iterating_lists.py
rainbow = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet']
index = 1
for item in rainbow:
    print(f'{index}. {item}')
    index+=1
Mark Sebeck
Mark Sebeck
Treehouse Moderator 38,297 Points

Actually if you are trying to get passed step one you just need to print(item). The second part you need to add the index.

1 Answer

Mark Sebeck
MOD
Mark Sebeck
Treehouse Moderator 38,297 Points

You created your own index. They want you to use the enumerate method like they showed in the video.

Bobur Azimov
Bobur Azimov
2,547 Points

is this structure correct ?

Any direction in how to do this? My code is the same as above provided by watching the video.

Mark Sebeck
Mark Sebeck
Treehouse Moderator 38,297 Points

Alana the above code will work in real life but the challenge wants you to use the enumerate method which was discussed in the second half of the video. Post your code if you still can't get it to pass.