Python Program to Print A-ABA-ABCBA Pattern Up To n Lines
This program prints A-ABA-ABCBA 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 66; print("%c" %(66))
which gives B
as output.
Python Source Code: A-ABA-ABCBA Pattern
# A-ABA-ABCBA pattern
# Reading number of rows
row = int(input('Enter how many lines? '))
a = 64
# Generating pattern
for i in range(1,row+1):
# for space
for j in range(1, row+1-i):
print(' ', end='')
# for increasing pattern
for j in range(1,i+1):
print('%c' %(a+j), end='')
# for decreasing pattern
for j in range(i-1,0,-1):
print('%c' %(a+j), end='')
# Moving to next line
print()
Output
Enter how many lines? 6 A ABA ABCBA ABCDCBA ABCDEDCBA ABCDEFEDCBA