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

时间:2017-02-10 01:08:53

标签: python

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

1 个答案:

答案 0 :(得分:0)

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 

打印此输出:

##
# #
#  #
#   #
#    #
#     #