Printing Simple Diamond Pattern in Python

后端 未结 15 2532
执笔经年
执笔经年 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:44

    As pointed out by Martin Evans in his post: https://stackoverflow.com/a/32613884/4779556 a possible solution to the diamond pattern could be:

    side = int(input("Please input side length of diamond: "))
    
    for x in list(range(side)) + list(reversed(range(side-1))):
        print('{: <{w1}}{:*<{w2}}'.format('', '', w1=side-x-1, w2=x*2+1))
    

提交回复
热议问题