Print shape in Python

后端 未结 1 2036
予麋鹿
予麋鹿 2020-12-12 07:39

In Python, I\'d like to print a diamond shape of asterisks *:

  • with $ at the top half of the diamond (upper pyramid) where there isn\'
相关标签:
1条回答
  • 2020-12-12 08:01
    def shape(n):
        for i in range(2*n+ 1):
            if (i < n):
                print "$" * (n - i) + "*" * 2 * i + "$" * (n - i)
            elif i == n:
                print "*" * 2 * n
            elif i > n:
                print "&" * (i - n) + "*" * 2 *  (2* n - i) + "&" * (i - n)
    
    0 讨论(0)
提交回复
热议问题