+1 vote
in Python by

Print the following pattern

     #

    # # 

   # # # 

  # # # # 

 # # # # #

1 Answer

0 votes
by
Code:

def pattern_7(num):

      

    # number of spaces is a function of the input num

    k = 2*num - 2

  

    # outer loop always handle the number of rows

    for i in range(0, num):

      

        # inner loop used to handle the number of spaces

        for j in range(0, k):

            print(end=" ")

      

        # the variable holding information about number of spaces

        # is decremented after every iteration

        k = k - 1

      

        # inner loop reinitialized to handle the number of columns  

        for j in range(0, i+1):

          

            # printing hash

            print("# ", end="")

      

        # ending line after each row

        print("\r")

 

num = int(input("Enter the number of rows: "))

pattern_7(n)

Related questions

+1 vote
asked Feb 15, 2021 in Python by SakshiSharma
0 votes
asked Jan 18, 2021 in Python by SakshiSharma
...