python循环嵌套例题
时间: 2023-09-26 12:08:08 浏览: 184
以下是一个Python循环嵌套的例题:
```python
n = 5
# 例题1:
for i in range(1, n+1):
for j in range(n, i-1, -1):
print(" ", end="\t")
print()
# 例题2:
for i in range(n, 0, -1):
for j in range(0, i):
print(" ", end="\t")
print()
# 例题3:
for i in range(1, n+1):
for j in range(1, i+1):
print(j, end="\t")
print()
```
在这个例子中,我们使用了三个不同的循环嵌套示例。第一个示例中,我们使用两个循环来打印一行行的空格。第二个示例中,我们使用两个循环来打印一行行的空格,但是顺序相反。第三个示例中,我们使用两个循环来打印一行行的数字,数字从小往大递增。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* *3* [Python中嵌套循环练习](https://blog.csdn.net/GaoXianGaoXian/article/details/129668474)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"]
[ .reference_list ]
阅读全文