Printing Simple Diamond Pattern in Python

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

    #maybe it could help  
    
    height = eval ( input ( 'How high? ' ) )
    height = int (height//2)
    
    for i in range(1, height+1):
        print(' ' *(height-i+1), '*'*i + '*' * (i-1) )
    
    for i in range (height+1, 0, -1):
        print (' ' * (height+1-i), '*' * i + '*' * (i-1))  
    

提交回复
热议问题