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

arielp
arielp
3,516 Points

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

this is annoying, is there a bug or something ..? I am asking to do:

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.

..if I check the code before pressing check work, I get this:

Output for iterating_lists.py

  1. red
  2. orange
  3. yellow
  4. green
  5. blue
  6. indigo
  7. violet .....yes!, the expected results.

...but then when summiting to using Check Work, I get this:

Bummer: AssertionError: '0' not found in '1. red\n2. orange\n3. yellow\n4. green\n5. blue\n6. indigo\n7. violet' : Whoops, don't forget to add a print statement to the for loop body that prints the index of each element in the list.

iterating_lists.py
rainbow = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet']

1 Answer

In task 2 you are asked to add a print statement above the existing print statement that prints the index of the current element. Indexing starts at zero. Your output should look like this:

0
red
1
orange
2
yellow
3
green
4
blue
5
indigo
6
violet