为技术面试做准备需要做大量准备,而且很可能您必须在那里创建Python模式程序。这就是为什么我们已经为Python中的模式打印列出了一个列表,以开始您的准备工作。
这个列表中有多种Python模式程序,所以请选择您的专业知识和经验。在进入下一个模式之前,请确保您了解代码的哪一部分所做的事情。如果不正确理解系统是如何工作的,您将面临很大的困难来解释它的工作。
很多时候,面试官要求你解释你是如何用Python进行模式打印的。了解每件事的工作原理将有助于你有效地回答这些问题。
您将发现Python代码以及下面的每一种模式:
模式1:简单数字三角形图案
模式:
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
代码:
Python
rows=6
fornuminrange(rows):
foriinrange(num):
print(num,end=”“)# print number
# line after each row to display pattern correctly
print(”“)
图2:倒金字塔
模式:
1 1 1 1 1
2 2 2 2
3 3 3
4 4
5
代码:
rows=5
b=0
foriinrange(rows,0,-1):
b+=1
forjinrange(1,i+1):
print(b,end=’‘)
print(‘\r’)
图3:半金字塔型数
模式:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
代码:
Python
rows=5
forrowinrange(1,rows+1):
forcolumninrange(1,row+1):
print(column,end=’‘)
print(“”)
模式4:下降数的倒金字塔
模式:
5 5 5 5 5
4 4 4 4
3 3 3
2 2
1
代码:
Python
rows=5
foriinrange(rows,0,-1):<