Printing Simple Diamond Pattern in Python

后端 未结 15 2601
执笔经年
执笔经年 2020-12-19 23:14

I would like to print the following pattern in Python 3.5 (I\'m new to coding):

    *
   ***
  *****
 *******
*********
 *******
  *****
   ***
    *
         


        
15条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-19 23:20

    a = 10
    for x in range (a):
      print(" " * (a - x) + "*" * (x+1) + "*" *(x))
    #+ this = diamond
    for x in reversed(range(a-1)):
        print(" " * (a - x) + "*" * (x) + "*" *(x+1))
    

提交回复
热议问题