Python Introducing Lists Using Lists Continental

Shavez Memon
Shavez Memon
Python Development Techdegree Student 2,440 Points

So 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.py
continents = [
    'Asia',
    'South America',
    'North America',
    'Africa',
    'Europe',
    'Antarctica',
    'Australia',
]
# Your code here

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

4 Answers

Steven Parker
Steven Parker
200,698 Points

You'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.

Steven Parker
Steven Parker
200,698 Points

The 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).

Shavez Memon
Shavez Memon
Python Development Techdegree Student 2,440 Points

Actually, this code prints all the continents, yet the requirement is to output only Asia and South America as the answer

Shavez Memon
Shavez Memon
Python Development Techdegree Student 2,440 Points

Hey, 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
Steven Parker
200,698 Points

I added a comment to my answer.

Shavez Memon
Shavez Memon
Python Development Techdegree Student 2,440 Points

Thanks 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
Steven Parker
200,698 Points

Check your indentation, otherwise it looks fine.

And when posting code to the forum, use Markdown formatting to preserve the appearance.