Hey guys, I'm looking for help with indexing in python. I'm supposed to print out continents that start with A only.
There are 7 continents and only those beginning with A are wanted.
continents = [ 'Asia', 'South America', 'North America', 'Africa', 'Europe', 'Antarctica', 'Australia', ] print("Continents:") for continent in continents: print("* " + continent) a = continents b = continents c = continents d = continents A = a + b + c + d print("Suggested continents:", A)
Steven Parker195,787 Points
You don't want to tie your code to specific indexes, what if the list gets changed later?
But your original loop will do the job, with just a conditional statement added to control the "print". So put an "if" statement before the "print" with an expression that compares the first character of the current continent with the letter "A".