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 trialWilliam Paterson
3,331 Pointscode in lesson not correct
i ended up copying the code in the lesson verbatim and still get an error message.
rainbow = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet']
for index color in enumerate(rainbow, 1):
print (f'{index}. {color}')
4 Answers
Michael Hulet
47,913 PointsYou have not copied this code verbatim. There is still a syntax error, though you're only 1 character off. the enumerate
function returns a tuple, so you need to have the tuple be properly unpacked. In your loop, you've written your 2 variables with nothing in between, which is invalid syntax in Python
William Paterson
3,331 PointsThank you but the second challenge isn't mentioned in the treehouse videos. "Edit the code so that the for loop uses the enumerate method. Add a print statement above the existing print statement that prints the index of the current element." I'm considering quitting, this is too agravating, everything makes sense but the workspace drives me insane.
Joshua Lewis
2,107 PointsJust a slight syntax error between index and color, besides that it looks great! Although you didn't need to copy the offset code verbatim.
Cory poweh
2,421 Pointsjust get rid off the 1. And separate the print function into two. should be written like this - for index, color in enumerate(rainbow): print(f"{index}. ") print(f"{color}")