Print a triangular pattern of asterisks

后端 未结 15 1060
慢半拍i
慢半拍i 2020-11-30 11:01

I am required to use nested for loops and print(\'*\', end=\' \') to create the pattern shown here:

And here is my code. I have figured out the first t

15条回答
  •  一个人的身影
    2020-11-30 11:14

    using spaces you can create different- different patterns: 1.

    def pattern(limit):
    
        for i in range(limit+1):
            print((limit-i)*"  "+ ' #'*i)    
    
    pattern(4)
    
    Output: 
           #
         # #
       # # #
     # # # #
    

    2.remove one space from above code and pattern will be changed in a pyramid

    def pattern(limit):
        for i in range(limit+1):
            print((limit-i)*" "+ ' #'*i)       
    pattern(4)
    
    output: #
           # #
          # # #
         # # # # 
    

    3: no space print((limit-i)*""+ ' #'*i) will create

     #
     # #
     # # #
     # # # #
    

提交回复
热议问题