PYTHON CORE · LESSON 10

Mini-project

List and loop together · about 15 minutes

Learning with progressRead the summary for free. To save the work, log in to the account.
STEP 1

Gather knowledge together.

The loop can go through every thing on the list. At each step, the variable gets the next thing.

pets = ["кот", "пёс"]
for pet in pets:
    print(pet)

✦ First there will be a cat, then a пёс.

STEP 2

Add words to every thing.

The line can be linked to the current list element. There will be a new message for each element.

pets = ["кот", "пёс"]
for pet in pets:
    print("Привет, " + pet)

✦ The same thing works for both pets.

IN-CLASS PRACTICE

Type the code yourself

Dial a small program from the sample. Find the list, loop and connection of lines.

pets = ["кот", "пёс"]
for pet in pets:
    print("Это " + pet)
Open the editor for class work
HOMEWORK

Solve it yourself

Create fruits with «яблоко», «груша», «банан». Loop through the list with for and a variable named fruit. Print «Фрукт: » and each fruit's name.

The answer is hidden. Use similar examples from the lesson notes.

Opening up your homework