Luyện tập
Viết vòng lặp while thêm "-ba" vào một chuỗi cho đến khi chuỗi dài hơn 30 ký tự. Bạn sẽ cần sử dụng len[]. Hãy thử trong vỏ IDLE.______1
Khám phá
Trong lập trình, vòng lặp được sử dụng để lặp lại một khối mã. Ví dụ: nếu chúng tôi muốn hiển thị thông báo 100 lần, thì chúng tôi có thể sử dụng vòng lặp. Đây chỉ là một ví dụ đơn giản, chúng ta có thể đạt được nhiều hơn nữa với các vòng lặp
Trong hướng dẫn trước, chúng ta đã tìm hiểu về vòng lặp for trong Python. Sau đây, chúng ta sẽ tìm hiểu về vòng lặp
# program to display numbers from 1 to 5
# initialize the variable
i = 1
n = 5
# while loop from i = 1 to 5
while i > wd = 'penguin'
>>> while len[wd] >> len[wd]
31
>>>
62Hành động>>> wd = 'penguin' >>> while len[wd] >> len[wd] 31 >>>63
>>> wd = 'penguin' >>> while len[wd] >> len[wd] 31 >>>64
# program to display numbers from 1 to 5
# initialize the variable
i = 1
n = 5
# while loop from i = 1 to 5
while i >> wd = 'penguin'
>>> while len[wd] >> len[wd]
31
>>>
66 được in. >>> wd = 'penguin' >>> while len[wd] >> len[wd] 31 >>>67 được tăng lên 2.
>>> wd = 'penguin' >>> while len[wd] >> len[wd] 31 >>>68
____164
# program to display numbers from 1 to 5
# initialize the variable
i = 1
n = 5
# while loop from i = 1 to 5
while i > wd = 'penguin'
>>> while len[wd] >> len[wd]
31
>>>
67 được tăng lên 3. # program to display numbers from 1 to 5
# initialize the variable
i = 1
n = 5
# while loop from i = 1 to 5
while i wd = 'penguin'
>>> while len[wd] >> len[wd]
31
>>>
67 được tăng lên 4. # program to display numbers from 1 to 5
# initialize the variable
i = 1
n = 5
# while loop from i = 1 to 5
while i wd = 'penguin'
>>> while len[wd] >> len[wd]
31
>>>
67 được tăng lên 5. # program to display numbers from 1 to 5
# initialize the variable
i = 1
n = 5
# while loop from i = 1 to 5
while i wd = 'penguin'
>>> while len[wd] >> len[wd]
31
>>>
67 được tăng lên 6. # program to display numbers from 1 to 5
# initialize the variable
i = 1
n = 5
# while loop from i = 1 to 5
while i