三角形组合成菱形

啥也不多少,先看看效果

---------------
    *
   ***
  *****
 *******
*********
 *******
  *****
   ***
    *
---------------

源码

print("---------------")
j=1 #1
while j<=5: #2<=5
    x=1 #x=1
    while x<=5-j:#1<=3
        print(" ",end="")#
        x+=1
    i = 1
    while i <= 2*j-1: #2<=1
        print("*", end="")  # *
        i += 1
    print()  # *
    #   ***
    j += 1
j=4 #1
while j>=1: #2<=5
    x=1 #x=1
    while x<=5-j:#1<=3
        print(" ",end="")#
        x+=1
    i = 1
    while i <= 2*j-1: #2<=1
        print("*", end="")#*
        i += 1
    print()#    *
           #   ***
    j-=1
print("---------------")

猜你喜欢

转载自www.cnblogs.com/liangliangzz/p/10317079.html
今日推荐