Quinten Rowland1,310 Points
how do I only print names of continents that start with the letter A?
I can print the list of continents after an asterisk, but I'm unsure how to filter it to only display the specific continent withing the list.
continents = [ 'Asia', 'South America', 'North America', 'Africa', 'Europe', 'Antarctica', 'Australia', ] # Your code here] continent = continents[0,3,5,6] for continent in continents: print("* " + continent)
Eric RyanPython Web Development Techdegree Student 16,968 Points
It looks like you are trying to manually select the continents that start with “A” and then iterate over every item in the new list and print each item. The way that you are trying to access the indices of the items in the “continents” list won’t work how you would expect as it’s written. The current code also won’t work because you are iterating over the variable “continents”, not the “continent” list that you are trying to create. Besides those issues though, what if the order of the “continents” list were to change? Then the “continent” list would likely be inaccurate.
What you should do is iterate over every item in the “continents” list and check to see if it starts with ‘A’. So you would write the code to say: For every continent in the list, if the first letter in the name of the continent (For example, continent) is equal to ‘A’, print an asterisk and then the name of the continent. If it’s not equal then continue iterating.