Share bài 10 trang 36 tin học 11 bằng python

## Bài 10: Trang 36 của Tin học 11 trong Python

### Mục tiêu học tập

* Hiểu cách sử dụng hàm `range ()` để lặp qua một chuỗi các số.
* Sử dụng vòng `for` để lặp qua một chuỗi các mục.
* Sử dụng câu lệnh `break` để thoát một vòng lặp sớm.
* Sử dụng câu lệnh `Tiếp tục 'để bỏ qua phần còn lại của phép lặp vòng lặp.

### Hàm `range ()`

Hàm `range ()` trả về một chuỗi các số từ giá trị bắt đầu sang giá trị cuối.Giá trị cuối cùng không được bao gồm trong chuỗi.

Cú pháp của hàm `range ()` là:

`` `Python
phạm vi (bắt đầu, kết thúc)
`` `

Trong đó `start` là giá trị bắt đầu của chuỗi và` end` là giá trị kết thúc của chuỗi.

Ví dụ: mã sau trả về một chuỗi các số từ 0 đến 9:

`` `Python
cho số trong phạm vi (10):
in (số)
`` `

Đầu ra:

`` `
0
1
2
3
4
5
6
7
số 8
9
`` `

### `for` vòng lặp

Vòng lặp `for` lặp qua một chuỗi các mục.Cú pháp của vòng `for` là:

`` `Python
Đối với mục theo trình tự:
# Làm gì đó với mục
`` `

trong đó `Chuỗi` là một chuỗi các mục.

Ví dụ: mã sau sử dụng vòng `for` để in các số từ 0 đến 9:

`` `Python
cho số trong phạm vi (10):
in (số)
`` `

Đầu ra:

`` `
0
1
2
3
4
5
6
7
số 8
9
`` `

### Câu lệnh `break`

Tuyên bố `break` có thể được sử dụng để thoát khỏi một vòng lặp sớm.Cú pháp của câu lệnh `break` là:

`` `Python
phá vỡ
`` `

Ví dụ: mã sau sử dụng câu lệnh `break` để thoát vòng lặp khi đạt được số 5:

`` `Python
cho số trong phạm vi (10):
Nếu số == 5:
phá vỡ
in (số)
`` `

Đầu ra:

`` `
0
1
2
3
4
5
`` `

### Tuyên bố `Tiếp tục`

Câu lệnh 'Tiếp tục' có thể được sử dụng để bỏ qua phần còn lại của một lần lặp vòng lặp.Cú pháp của câu lệnh 'Tiếp tục' là:

`` `Python
Tiếp tục
`` `

Ví dụ: mã sau sử dụng câu lệnh 'Tiếp tục' để bỏ qua số 5 khi lặp lại các số từ 0 đến 9:

`` `Python
cho số trong phạm vi (10):
Nếu số == 5:
Tiếp tục
in (số)
`` `

Đầu ra:

`` `
0
1
2
3
4
6
7
số 8
9
`` `

### hashtags

* #Python
* #Programming
* #Loops
* #Iteration
* #phá vỡ
* #tiếp tục
=======================================
## Lesson 10: Page 36 of Informatics 11 in Python

### Learning Objectives

* Understand how to use the `range()` function to iterate over a sequence of numbers.
* Use the `for` loop to iterate over a sequence of items.
* Use the `break` statement to exit a loop early.
* Use the `continue` statement to skip the rest of a loop iteration.

### The `range()` Function

The `range()` function returns a sequence of numbers from a start value to an end value. The end value is not included in the sequence.

The syntax of the `range()` function is:

```python
range(start, end)
```

where `start` is the starting value of the sequence and `end` is the ending value of the sequence.

For example, the following code returns a sequence of numbers from 0 to 9:

```python
for number in range(10):
print(number)
```

Output:

```
0
1
2
3
4
5
6
7
8
9
```

### The `for` Loop

The `for` loop iterates over a sequence of items. The syntax of the `for` loop is:

```python
for item in sequence:
# do something with item
```

where `sequence` is a sequence of items.

For example, the following code uses a `for` loop to print the numbers from 0 to 9:

```python
for number in range(10):
print(number)
```

Output:

```
0
1
2
3
4
5
6
7
8
9
```

### The `break` Statement

The `break` statement can be used to exit a loop early. The syntax of the `break` statement is:

```python
break
```

For example, the following code uses a `break` statement to exit the loop when the number 5 is reached:

```python
for number in range(10):
if number == 5:
break
print(number)
```

Output:

```
0
1
2
3
4
5
```

### The `continue` Statement

The `continue` statement can be used to skip the rest of a loop iteration. The syntax of the `continue` statement is:

```python
continue
```

For example, the following code uses a `continue` statement to skip the number 5 when iterating over the numbers from 0 to 9:

```python
for number in range(10):
if number == 5:
continue
print(number)
```

Output:

```
0
1
2
3
4
6
7
8
9
```

### Hashtags

* #Python
* #Programming
* #Loops
* #Iteration
* #Break
* #continue
 
Join Telegram ToolsKiemTrieuDoGroup
Back
Top