如何使用嵌套循环在Python中创建这个形状?

2024-05-15 14:41:29 发布

您现在位置:Python中文网/ 问答频道 /正文

编写一个使用嵌套循环绘制此模式的程序。(14) 底页


Tags: 程序模式绘制嵌套循环底页
1条回答
网友
1楼 · 发布于 2024-05-15 14:41:29
for row in range(6):                 # this outer loop computes each of the 6 lines
   line_to_print = '#'
   for num_spaces in range(row):     # this inner loop adds the desired number or spaces to the line
       line_to_print  = line_to_print + ' '
   line_to_print = line_to_print + '#'
   print line_to_print 

打印此输出:

^{pr2}$

相关问题 更多 >