+1 vote
in Python by
Print the following pattern in python

1

2 3

4 5 6

7 8 9 10

11 12 13 14 15

1 Answer

0 votes
by

Below is the code to draw the pattern

Code: 

def pattern_4(num): 

      

    # initialising starting number  

    number = 1

    # outer loop always handles the number of rows 

    # let us use the inner loop to control the number 

   

    for i in range(0, num): 

      

        # commenting the reinitialization part ensure that numbers are printed continuously

        # ensure the column starts from 0

        number = 0

      

        # inner loop to handle number of columns 

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

          

                # printing number 

            print(number, end=" ") 

          

            # increment number column wise 

            number = number + 1

        # ending line after each row 

        print("\r") 

  

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

pattern_4(num)

Related questions

+1 vote
asked Feb 15, 2021 in Python by SakshiSharma
+1 vote
asked Jan 30, 2022 in Python by sharadyadav1986
...