in Python by
Q:

Print the following pattern

     #

    # # 

   # # # 

  # # # # 

 # # # # #

► Click here to show 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)
Python
Learn More with Madanswer

Related questions

+1 vote
asked Feb 15 in Python by SakshiSharma
...