62.4k views
1 vote
write a for loop that iterates over the elements of months and prints out each one that begins with letter "J",one month per line.(using python)

User Ran Avnon
by
6.7k points

2 Answers

5 votes
Hello alanagarcia. When posting coding questions you should show some of the work you have tried. After all this is in the college section. Normally I will delete these types of posts if no work has been shown or if the poster does not tell us what type of language they are using. Since you gave us the language, the following code will do what you need it to do. Next time show a little work please. TY.

monthlist = [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December']

for month in monthlist:
if "J" in month:
print(month)
User BigRedDog
by
6.7k points
7 votes

Answer and Explanation

A for loop is a control flow of statement for specifying iteration, which allows a code to be executed repeatedly. For-loops are typically used when the number of iterations is known before entering the loop.

months = ['January', 'July', 'Nov']

for i in months:

i = i.lower()

if (i.lower()).startswith('j'):

print(i)


User Supputuri
by
6.4k points