Загрузка страницы

How to check a number in a list using a for loop in Python? Examples + exercises

#python #forloops #forloopspython #countinginforloops #magicnumber

Exercises:

1. How many numbers are there in this list?

[212, 111, 102, 201, 212, 122, 210, 101, 211, 222, 212, 202, 102, 211, 201, 212, 110, 212, 220, 221, 102, 121]

2. How many of the number:

212
102
100
111

are there in the following list?

[212, 111, 102, 201, 212, 122, 210, 101, 211, 222, 212, 202, 102, 211, 201, 212, 110, 212, 220, 221, 102, 121]

Use a loop for to answer.

______________________________________________________________________________________

Note:
7:12 - I forgot to write a colon sign after NUMBER_TO_CHECK. I am sorry for that error.

Let's remember for loops. We were already talking about them in the first Python course.
How to count the number of elements in a list using a for loop in Python?

The list from the examples:

[19,3,19,22]

Sometimes we replace the iteration variable by the underscore.

How many numbers 19 are there in this list [19,3,19,22]?

We created a new variable and named it NUMBER_TO_CHECK in order to avoid the situation with a "magic number".
Python course #2 in English 9
Python programming language course in English

#underscore #pythonexercises #pythontasks #python程式設計語言 #python程式設 #程式設計語言 #程式設

Видео How to check a number in a list using a for loop in Python? Examples + exercises канала Olga Soboleva
Показать
Комментарии отсутствуют
Введите заголовок:

Введите адрес ссылки:

Введите адрес видео с YouTube:

Зарегистрируйтесь или войдите с
Информация о видео
14 июля 2020 г. 18:57:19
00:18:02
Яндекс.Метрика