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

Need help in this objective

Hello guys. i've been in the 2nd objective from the 2nd unit in "Introducing lists course" i've been trying for 2 weeks to solve the 2nd objective. I Tried everything printing every single continent that begins with the letter "A" Or using a if statement the prints the rest in less lines of code. I Tried functions. I Tried everything. Please. Even though i reached through this community and stack overflows to search for answer. So

Give me a answer and why it's solved like that

This is in-case you aren't familliar with it but have experience.

continents.py
continents = [
    'Asia',
    'South America',
    'North America',
    'Africa',
    'Europe',
    'Antarctica',
    'Australia',
]
# Your code here
for continent in continents:
    print(continents[0])
    print(continents[3])
    print(continents[5])
    print(continents[6])

2 Answers

Robin Goyal
Robin Goyal
4,582 Points

You have to print a bulleted list of continents that start with the letter A so that means:

* Asia
* Africa
* Antarctica
* Australia

Now in regards to your code, you don't want to print out the continents starting with the letter A by hardcoding the indices that they're located. These locations of the continents in the list could always change so you want to have code that will work on any list with any elements.

Here is pseudocode:

- loop through each continent in continents:
  - if a continent starts with the letter A
    - print that continent

Python solution:

for continent in continents:
    if continent[0] == "A":
        print("* {}".format(continent))

Thanks man, really appreciate it Even though that i did that but instead of writing .format() i wrote a comma followed by continent. Couldn't belive it i was this close to answering

The problem with this challenge is the previous question specifically asked for the "*" asterisk to be outputted.

Whereas this challenge states - loop through each continent in continents:

  • if a continent starts with the letter A
    • print that continent

It does state "print that continent beginning with a "*" "

Thats where the confusion is.