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
timoleodilo
1,438 PointsPrint 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])
17 Answers
Steven Parker
243,318 PointsDid 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.
Mitchell Beck
5,836 PointsThis worked for me:
continents = [
'Asia',
'South America',
'North America',
'Africa',
'Europe',
'Antarctica',
'Australia',
]
for continent in continents:
print ('*', continent)
Jan Baláž
576 PointsHi, 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.
timoleodilo
1,438 Pointshow do I display each item in a string format. have 2 print outputs you saying?
jon nikolakakis
1,639 PointsYou 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
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`
timoleodilo
1,438 Pointsthis is what the output should look like:
* Asia
* South America
Moritz Wallawitsch
736 PointsI dont get in too. Can anyone tell me the answer?
Steven Parker
243,318 PointsGive it your best "good faith" try, and if you still have trouble, start a new question and post your revised code with it.
John Napier
14,383 PointsTo 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.
leejay cardoza
2,040 PointsThis is the answer: for continent in continents: print("* " + continent)
Mercedes Aker
6,544 PointsSorry this isn't actually accepted
aaronrolle
622 Pointslmaooo -2 idk why this so funny
John Silva
2,741 Pointsthis is what worked for me
for continent in continents: print("* " + continent)
Luke Shephard Zikuyumo
1,655 PointsFor continent in continents: Print("*" , continent)
It work for me on the first task
Ravi Batra
2,486 PointsThis is the code that worked for me
for x in continents:
print("* " + x)
Steven Parker
243,318 PointsI'm moved to mention that Treehouse has traditionally discouraged explicit solutions without any explanations.
Ravi Batra
2,486 PointsThanks for the tips, @Steven Parker! Also -- VERY impressive profile! You are inspiring.Thanks for always helping the Treehouse Community!
Mike Siwik
Full Stack JavaScript Techdegree Student 8,483 Pointsfor 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
243,318 PointsOnce again: Treehouse has traditionally discouraged explicit solutions without explanations.
timoleodilo
1,438 PointsI'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
243,318 PointsYou only need one "print" statement, and "continent" (singular) is a string. You don't need to use an index on it.
Hessah Alhamadi
1,109 PointsTry this solution :
for item in continents : print ("* " + item)
Deshbir Sandhu
439 Pointscontinents = [ 'Asia', 'South America', 'North America', 'Africa', 'Europe', 'Antarctica', 'Australia', ] for item in continents[0:2]: print('*',item) Output:
- Asia
- South America
Steven Parker
243,318 PointsDid 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.
Patrick Bain
Python Development Techdegree Student 2,592 PointsWhat does the asterisk mean?
Kudakwashe Moyo
3,811 Pointsthis worked for me
for continent in continents: print("*", continent)
Marissa Lainhart
9,293 PointsThis answer is correct. Edited 05/16, tried this solution again, did not work this time
timoleodilo
1,438 Pointstimoleodilo
1,438 Pointsthis is the error that I get : Oh no, there were 2 problems with your code, check the preview pane for more information