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 Introducing Lists Using Lists Continental

Michael Kaminski
Michael Kaminski
1,419 Points

I can't seem to get the for loop to print the 2 continents only one time, and I want to know how to run a for loop once.

For the continental code challenge I enter a for loop to iterate through the list of continents

continents = ['Asia','South America', 'North America', 'Africa', 'Europe', 'Antarctica', Australia']

I enter for continent in continents: print("* ",continent[0]) print("* ",continent[1])

This gives me the right answer but repeats it forever. I thought we had to use a for loop, and I am confused as to how to make it just go through the list and print it out just one time.

continents.py
continents = [
    'Asia',
    'South America',
    'North America',
    'Africa',
    'Europe',
    'Antarctica',
    'Australia',
]
# Your code here
for x in range(0,1):
    for continent in continents:
        print("* ",continents[0])
        print("* ",continents[1]) 

1 Answer

Steven Parker
Steven Parker
231,248 Points

Here's some hints:

  • you only need one loop
  • you also only need one "print" statement
  • the print statement should use the loop variable to print a different name each time
  • indexing is not needed for this task