Lists and for loops 1

Lists and for loops

for number in range(20):
    if number % 3 == 0:
        print(number)

for fruit in ["banana", "apple", "quince"]:
    print("I like to eat " + fruit + "s!")

Here is what the above code is Doing:
1. The first line creates a list of numbers from 0 to 19.
2. The second line says that for each number in that list, check to see if it’s divisible by 3.
3. If it is, print the number.
4. If it isn’t, do nothing.
5. The third line creates a list of strings.
6. The fourth line says that for each string in that list, print a sentence using the string.

Similar Posts