Print a triangular pattern of asterisks

后端 未结 15 1040
慢半拍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:15

    i=0
    while(i<5):
        j=0
        while(j<=i):
            print("*",end="") #end="" is given to stay on same line
            j=j+1
        print("")  #it will take u to new line
        i=i+1
        j=0
    i=i-2
    j=i
    while(i>=0):
        while(j>=0):
            print("*",end="")
            j=j-1
        print() #will also work
        i=i-1
        j=i
    

    this will also work

提交回复
热议问题