Print ABA Alphabet Pyramid Python Program

By | March 27, 2020

Topic: Print ABA Alphabet Pyramid Python Program Pattern No. 12

Python Print ABA Alphabet Pyramid Pattern

Python Print ABA Alphabet Pyramid Pattern

The Source Code of Print ABA Alphabet Pyramid

# Python 3 program
# to print Alphabet Pattern-12
# as shown below

# Ascii code of A=65,E=69,F=70
# Print certain number of spaces before alphabets

ch = 'A'
# outer loop for ith rows
for i in range (1,rows+1):
    for space in range(rows-i):
        print(' ',end='')

    # this loop will print    
    #     A
    #    AB
    #   ABC
    #  ABCD
    # ABCDE
    for j in range(1, i+1):
        ch = chr(ch)
    ch = chr(ch)
    # this loop will print remaining pattern
    # after center line
    #    A
    #    BA
    #    CBA
    #    DCBA

    for k in range(1, i):
        ch = chr(ch)

How this Python Program works?

The first for loop is for the total number of lines or rows to be printed

The second for loop will print the required number of spaces.

The third for loop prints the first half party of the alphabetic pyramid.

The fourth for loop will print the remaining half alphabets pyramid.

What is the Use of chr() function and ord() function in Python

chr() function in Python

The chr() function in Python takes an integer Ascii code and returns the character (actually a string of one character)at that Ascii code value. For example , chr(65) will return ‘A’ and chr(97) will give ‘a’.

Note that the argument must be in the range [0..255], inclusive; Otherwise, ValueError will be raised if i is outside that range.

ord() function in Python

ord() function takes a string of length one (single character) as an argument and returns an integer representing the Unicode code point of that character when the argument is a unicode object, or the value of the byte when the argument is an 8-bit string. For example, ord(‘A’) gives 65 and ord(‘a’) returns the integer 97.

Python 3 Programs for 11 Alphabets Patterns, Pyramids, Triangles,Squares, Shapes

Python Print Alphabet Patterns Programs

(11 Programs)

 14,677 total views,  26 views today

One thought on “Print ABA Alphabet Pyramid Python Program

  1. Pingback: Python Print Alphabet Patterns 11 Programs |

Leave a Reply

Your email address will not be published. Required fields are marked *