Python程序打印正方形的右增量字母图案

43 阅读1分钟

编写一个Python程序,使用for循环打印右增量字母的正方形图案。

rows = int(input("Enter Square of Right Increment Alphabets Rows = " ))

print("====The Square of Right Incremented Alphabets Pattern====") alphabet = 65

for i in range(rows): for j in range(rows - 1, i, -1): print('A', end = ' ') for k in range(i + 1): print('%c' %(alphabet + i), end = ' ' ) print()

image.png

这个Python程序使用一个while循环,从右侧打印出增量字母的方形图案。

rows = int(input("Enter Square of Right Increment Alphabets Rows = " ))

print("====The Square of Right Incremented Alphabets Pattern====") alphabet = 65 i = 0

while(i < rows): j = rows - 1 while(j > i): print('A', end = ' ') j = j - 1 k = 0 while(k <= i): print('%c' %(alphabet + i), end = ' ') k = k + 1 print() i = i + 1
Enter Square of Right Increment Alphabets Rows = 12
====The Square of Right Incremented Alphabets Pattern====
A A A A A A A A A A A A 
A A A A A A A A A A B B 
A A A A A A A A A C C C 
A A A A A A A A D D D D 
A A A A A A A E E E E E 
A A A A A A F F F F F F 
A A A A A G G G G G G G 
A A A A H H H H H H H H 
A A A I I I I I I I I I 
A A J J J J J J J J J J 
A K K K K K K K K K K K 
L L L L L L L L L L L L