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

A

B B

C C C

D D D D

1 Answer

0 votes
by

Below is the program to draw the pattern in python:

def pattern_5(num): 

    # initializing value of A as 65

    # ASCII value  equivalent

    number = 65

  

    # outer loop always handles the number of rows 

    for i in range(0, num): 

      

        # inner loop handles the number of columns 

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

          

            # finding the ascii equivalent of the number 

            char = chr(number) 

          

            # printing char value  

            print(char, end=" ") 

      

        # incrementing number 

        number = number + 1

      

        # ending line after each row 

        print("\r") 

  

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

pattern_5(num)

Related questions

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