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

Print a bulleted list of each continent from the continents list. Output should look similar to:

continents = ['Asia', 'South America', 'North America', 'Africa', 'Europe', 'Antarctica', 'Australia'] for continent in continents: print("* ", +continents[:1])

this is the error that I get : Oh no, there were 2 problems with your code, check the preview pane for more information

continents = ['Asia', 'South America', 'North America', 'Africa', 'Europe', 'Antarctica', 'Australia']
for continent in continents:
    print("* ", +continents[:1])

17 Answers

Steven Parker
Steven Parker
243,318 Points

Did you look at the preview? It had "TypeError: bad operand type for unary +: 'list'"

That's a hint that you don't want that "+" sign in front of your argument.

Also, that slice is always taking just the first item from the list, and returning it inside a list. What you really want is to display each item in sequence, as a string. The loop conveniently puts that into the variable "continent" (singluar) for you.

This worked for me:

continents = [
    'Asia',
    'South America',
    'North America',
    'Africa',
    'Europe',
    'Antarctica',
    'Australia',
]
for continent in continents:
    print ('*', continent)

Hi, I don't understand why are you put for "continent" - why is it continent and not continents? I do not get it....Thank you for help.

how do I display each item in a string format. have 2 print outputs you saying?

You need to have a space in between the asterix.

continents = [
    'Asia',
    'South America',
    'North America',
    'Africa',
    'Europe',
    'Antarctica',
    'Australia',
]
for x in continents:
    print("* "+ x)
Megan L
Megan L
2,906 Points

*Note: for this exercise, it is quite buggy about the answers it will accept. It will even mark it as an error for something minor like indentation or spacing. *

for continent in continents: print("* " + continent)

This is the correct answer and what has worked. There is a space after the asterisk.

for continent in continents: print("* " + continent)

`Correct Output shown on right side in test results: Output for continents.py

  • Asia
  • South America
  • North America
  • Africa
  • Europe
  • Antarctica
  • Australia`

this is what the output should look like:

* Asia
* South America

I dont get in too. Can anyone tell me the answer?

Steven Parker
Steven Parker
243,318 Points

Give it your best "good faith" try, and if you still have trouble, start a new question and post your revised code with it.

To get the same results, one could also use this : print("*", continent) See the difference? No space after the * because the comma then iteration variable places a space for you.

print("* " + continent) print("*", continent)

the exercise won't accept the this answer but it is just as valid.

This is the answer: for continent in continents: print("* " + continent)

Sorry this isn't actually accepted

lmaooo -2 idk why this so funny

this is what worked for me

for continent in continents: print("* " + continent)

For continent in continents: Print("*" , continent)

It work for me on the first task

This is the code that worked for me

for x in continents: 
     print("* " + x)
Steven Parker
Steven Parker
243,318 Points

I'm moved to mention that Treehouse has traditionally discouraged explicit solutions without any explanations. :see_no_evil:

Thanks for the tips, @Steven Parker! Also -- VERY impressive profile! You are inspiring.Thanks for always helping the Treehouse Community!

Mike Siwik
seal-mask
.a{fill-rule:evenodd;}techdegree
Mike Siwik
Full Stack JavaScript Techdegree Student 8,483 Points
for continent in continents:
      if continent[0] == 'A':
          print('*', continent)

It should be written this way to avoid indentation errors. Read the hints carefully. And watch the videos leading up to this, it'll make it easier to figure out.

Steven Parker
Steven Parker
243,318 Points

Once again: Treehouse has traditionally discouraged explicit solutions without explanations. :see_no_evil:

I'm still getting an error. not sure how to display each item as a string.

continents = ['Asia', 'South America', 'North America', 'Africa', 'Europe', 'Antarctica', 'Australia']
for continent in continents:
    print("*", continent[0])
    print("*", continent[1])
Steven Parker
Steven Parker
243,318 Points

You only need one "print" statement, and "continent" (singular) is a string. You don't need to use an index on it.

Try this solution :

for item in continents : print ("* " + item)

continents = [ 'Asia', 'South America', 'North America', 'Africa', 'Europe', 'Antarctica', 'Australia', ] for item in continents[0:2]: print('*',item) Output:

  • Asia
  • South America
Steven Parker
Steven Parker
243,318 Points

Did you try that in the challenge? It says "Hmm...not finding the correct items in your output".
Hint: for task 1 you want to print the entire list, not just part of it.

What does the asterisk mean?

this worked for me

for continent in continents: print("*", continent)

This answer is correct. Edited 05/16, tried this solution again, did not work this time