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

brownbird187

New member
## 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 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ố, bắt đầu từ một giá trị bắt đầu được chỉ định và kết thúc với một giá trị cuối được chỉ định.Giá trị cuối cùng không được bao gồm trong chuỗi.

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

`` `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
`` `

### 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âu lệnh `break` thường được sử dụng khi một điều kiện được đáp ứng cho thấy vòng lặp nên được chấm dứt.

Ví dụ: mã sau sử dụng câu lệnh `break` để thoát vòng lặp khi người dùng nhập chữ cái` q`:

`` `Python
Trong khi đúng:
user_input = input ("Nhập một chữ cái:")

Nếu user_input == "q":
phá vỡ

in ("bạn đã nhập chữ cái" + user_input)
`` `

### 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âu lệnh 'Tiếp tục' thường được sử dụng khi một điều kiện được đáp ứng cho thấy rằng lần lặp hiện tại của vòng lặp nên được bỏ qua.

Ví dụ: mã sau sử dụng câu lệnh 'Tiếp tục' để bỏ qua phần còn lại của lần lặp vòng lặp khi người dùng nhập chữ cái `Q`:

`` `Python
Trong khi đúng:
user_input = input ("Nhập một chữ cái:")

Nếu user_input == "q":
Tiếp tục

in ("bạn đã nhập chữ cái" + user_input)
`` `

### Phần kết luận

Chức năng `range ()`, câu lệnh `break` và câu lệnh 'Contern` là tất cả các công cụ hữu ích để kiểm soát luồng chương trình của bạn.Bằng cách hiểu cách sử dụng các câu lệnh này, bạn có thể viết mã hiệu quả và dễ đọc hơn.

### hashtags

* #Python
* #Programming
* #loops
* #Conditionals
* #kiểm soát dòng chảy
=======================================
## 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 `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, starting from a specified start value and ending with a specified end value. The end value is not included in the sequence.

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

```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 `break` Statement

The `break` statement can be used to exit a loop early. The `break` statement is typically used when a condition is met that indicates that the loop should be terminated.

For example, the following code uses the `break` statement to exit a loop when the user enters the letter `q`:

```python
while True:
user_input = input("Enter a letter: ")

if user_input == "q":
break

print("You entered the letter " + user_input)
```

### The `continue` Statement

The `continue` statement can be used to skip the rest of a loop iteration. The `continue` statement is typically used when a condition is met that indicates that the current iteration of the loop should be skipped.

For example, the following code uses the `continue` statement to skip the rest of the loop iteration when the user enters the letter `q`:

```python
while True:
user_input = input("Enter a letter: ")

if user_input == "q":
continue

print("You entered the letter " + user_input)
```

### Conclusion

The `range()` function, `break` statement, and `continue` statement are all useful tools for controlling the flow of your programs. By understanding how to use these statements, you can write more efficient and readable code.

### Hashtags

* #Python
* #Programming
* #loops
* #Conditionals
* #control-flow
 
Join ToolsKiemTrieuDoGroup
Back
Top
AdBlock Detected

We get it, advertisements are annoying!

Sure, ad-blocking software does a great job at blocking ads, but it also blocks useful features of our website. For the best site experience please disable your AdBlocker.

I've Disabled AdBlock