Python Program To Print A-AB-ABC-ABCD Pattern Up To n Lines


This python program prints or generates A-AB-ABC-ABCD pattern up to n lines given by user.


In this program %c is used for displaying corresponding ASCII character of a number. For example to display ASCII character corresponding to 65; print("%c" %(65)) which gives A as output.

Python Source Code: A-AB-ABC-ABCD Pattern


# A-AB-ABC-ABCD Pattern up to n lines

n = int(input("Enter number of rows: "))

for i in range(1,n+1):
    a = 65
    for j in range(1, i+1):
        print("%c" %(a), end="")
        a +=1
    print()

Output

Enter number of rows: 10
A
AB
ABC
ABCD
ABCDE
ABCDEF
ABCDEFG
ABCDEFGH
ABCDEFGHI
ABCDEFGHIJ