Python Program To Print A-ABC-ABCDE Pattern Up To n Lines
This python program prints or generates A-ABC-ABCDE 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-ABC-ABCDE Pattern
# Pattern A-ABC-ABCDE ...
# Reading number of rows
row = int(input('Enter how many lines? '))
a = 65 # ASCII value for 'A'
# Generating pattern
for i in range(1,row+1):
# for space
for j in range(1, row+1-i):
print(' ', end='')
# for pattern
for j in range(0, 2*i-1):
print('%c' % (a+j), end='')
# Moving to next line
print()
Output
Enter how many lines? 7 A ABC ABCDE ABCDEFG ABCDEFGHI ABCDEFGHIJK ABCDEFGHIJKLM