Python中的简单图案打印程序
Pattern 1:
模式1:
*
* *
* * *
最烧脑的十部电影* * * *
c语言数组实现栈* * * * *
Code:
码:
for row in range (0,5):
for column in range (0, row+1):
print ("*", end="")
power是什么软件# ending row
print('\r')
Pattern 2:
模式2:
Now if we want to print numbers or alphabets in this pattern then we need to replace the ** with the desired number you want to replace. Like if we want pattern like,
现在,如果要在此模式下打印数字或字母,则需要将**替换为要替换的所需数字。 就像我们想要图案⼀样
1
1 1
1 1 1
1 1 1 1
1 1 1 1 1
Code:
码:
#row operation
for row in range(0,5):
# column operation
for column in range(0,row+1):
print("1 ",end="")
# ending line
print('\r')
Pattern 3:
模式3:
If want increasing numbers in this pattern like,
如果要以这种模式增加数字,
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Here we need to declare a starting number from which the patter will start. In the above case the nu
mber is starting from 1. So, here we have to create a variable and assigns its value to 1 then we need to print only the value of variable.
在这⾥,我们需要声明⼀个起始编号,从该起始编号开始。 在上述情况下,数字从1开始。因此,这⾥我们必须创建⼀个变量并将其值分配为1,然后只需要打印变量的值即可。
As its value is increasing every row by 1, but starting value is always 1.
由于其值每⾏增加1,但起始值始终为1。
So, for that we have to declare the value of the starting number before column operation (second for loop) and need to increase it by 1 after the column operation section after the printing value.
因此,为此,我们必须在列运算之前声明起始编号的值(循环的第⼆个),并且需要在打印值后的列运算部分之后将起始编号增加1。
Code:
码:
#row operation
for row in range (0, 5):
n = 1
# column operation
for column in range (0, row+1):
print(n, end=" ")
n = n+1
# ending line
print('\r')
Pattern 4:
伪指令大全模式4:
1
2 3
4 5 6
7 8 9 10
11 12 13 14
To get the above pattern only we have to declare the variable before the row operation. Follow the code below,
为了获得上述模式,我们只需要在⾏操作之前声明变量。 请遵循以下代码,
Code:
码:
n = 1
#row operation
for row in range (0, 5):
# column operation
for column in range (0, row+1):
print(n, end=" ")
n = n+1
# ending line
mariadb安装大小print('\r')
Pattern 5:
模式5:
A
A B
A B C
A B C D
A B C D E
The above pattern can also be another type.
上⾯的模式也可以是其他类型。
For that should have the knowledge of of 'A'.
为此,应具有 “ A”的知识。
Its is 65.
其 65。
In column operation We have to convert the ASCII value to character using .在列操作中,我们必须使⽤将ASCII值转换为字符。
Code:
码:
#row operation
for row in range (0, 5):
n = 65
python代码画图案# column operation
for column in range (0, row+1):
c = chr(n)
print(c, end=" ")
n = n+1
# ending line
print('\r')
Practice more python experiences here:
在这⾥练习更多python经验:
翻译⾃:
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论