Print a triangular pattern of asterisks

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

    for i in range (1,n):    # loop will execute from 1 to 4(n-1)
        for j in range(1,i+1):
            print("*",end="")
        print()
    for i in range (n+1,1,-1):
        for j in range(i,1,-1):
            print("*",end="")
        print()
    

    using for loop

提交回复
热议问题