2019-02-21
阅读量:
591
如何用for输出简单的金字塔?
可以使用简单的for循环在python中打印模式。第一外环是用来处理的行数和内部嵌套循环来处理的列数。可以打印操作打印报表,不同的数字模式,字母图案或星形图案。
- 简单的金字塔模式
# Python 3.x code to demonstrate star pattern
# Function to demonstrate printing pattern
def pypart(n):
# outer loop to handle number of rows
# n in this case
for i in range(0, n):
# inner loop to handle number of columns
# values changing acc. to outer loop
for j in range(0, i+1):
# printing stars
print("* ",end="")
# ending line after each row
print("\r")
# Driver Code
n = 5
pypart(n)
输出:
*
* *
* * *
* * * *
* * * * *






评论(0)


暂无数据
推荐帖子
0条评论
0条评论
0条评论