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 trialShavez Memon
Python Development Techdegree Student 2,452 PointsSo what is the solution?
Hi, I'm using this code which is printing all the continents but how do I print just Asia and South America? Thanks a ton!
continents = [
'Asia',
'South America',
'North America',
'Africa',
'Europe',
'Antarctica',
'Australia',
]
# Your code here
for continent in continents:
print('*' + continent)
4 Answers
Steven Parker
231,198 PointsYou're almost there! You just need to add a space to prevent the 'bullet" from being against the name:
print('* ' + continent)
Task 1 is to print all continents. Task 2 is to print only those beginning with "A" (which would not include "South America" since it begins with "S")..
If you're working on task 2 you'll need to add an "if" statement that isolates the first letter and compares it with "A". But both tasks require the output to have a "bullet" and a space before the name.
Shavez Memon
Python Development Techdegree Student 2,452 PointsActually, this code prints all the continents, yet the requirement is to output only Asia and South America as the answer
Shavez Memon
Python Development Techdegree Student 2,452 PointsHey, thank you for clarifying. Also, I'm struggling with Task2. My code is below. Could you tell me what I can fix?
if continents[0] == 'A':
print (continents)
Steven Parker
231,198 PointsI added a comment to my answer.
Shavez Memon
Python Development Techdegree Student 2,452 PointsThanks for responding. I think I did as you told for Task2 and I still get an error:
if continent[0] == 'A':
print('* ' + continent)
Steven Parker
231,198 PointsCheck your indentation, otherwise it looks fine.
And when posting code to the forum, use Markdown formatting to preserve the appearance.
Steven Parker
231,198 PointsSteven Parker
231,198 PointsThe task 2 "if" should test "continent" (singular) instead of the whole "continents" list.
And the "print" statement should be the same as for task 1 (with the "bullet" and space).