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 trialBobur Azimov
2,547 PointsWrite 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 ...
rainbow = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet']
index = 1
for item in rainbow:
print(f'{index}. {item}')
index+=1
1 Answer
Mark Sebeck
Treehouse Moderator 38,297 PointsYou created your own index. They want you to use the enumerate method like they showed in the video.
Bobur Azimov
2,547 Pointsis this structure correct ?
Alana Warson
5,296 PointsAny direction in how to do this? My code is the same as above provided by watching the video.
Mark Sebeck
Treehouse Moderator 38,297 PointsAlana 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.
Mark Sebeck
Treehouse Moderator 38,297 PointsMark Sebeck
Treehouse Moderator 38,297 PointsActually if you are trying to get passed step one you just need to print(item). The second part you need to add the index.