in Python by
Q:

Print the following pattern:

0

0 1

0 1 2

0 1 2 3

0 1 2 3 4

► Click here to show 1 Answer

0 votes
by

Below is the Code to draw the pattern in python

def pattern_3(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): 

      

        # re assigning number after every iteration

        # 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_3(num)

Python
Learn More with Madanswer

Related questions

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