Python Program to Print a-ab-abc-abcd Pattern up To n Lines


This program prints (generates) a-ab-abc-abcd pattern up to n lines given by user in Python programming language.


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 Pattern


# a-ab-abc-abcd-abcde Pattern up to n lines

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

for i in range(1,n+1):
    a = 97
    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