etutorialspoint
  • Home
  • PHP
  • MySQL
  • MongoDB
  • HTML
  • Javascript
  • Node.js
  • Express.js
  • Python
  • Jquery
  • R
  • Kotlin
  • DS
  • Blogs
  • Theory of Computation

Alphabet pattern programs in Python

In this post, you will learn how to print various alphabetic patterns using the Python programming language.

An alphabetical pattern is a series of alphabet (A-Z) that form a pattern or any shape like a pyramid, triangle, square, rhombus, etc. The alphabet pattern programs are very important for new developers. It improves the thinking power and logical building ability in computer programming.





A pattern program consists of patterns of numbers, letters, and symbols in a particular form. In the programming language, the loop condition is considered important for printing patterns. Generally, nested loops may be used in alphabet patterns and shape printing programs.





The alphabet pattern programs need an ASCII code to print a letter. Like, the chr(65) function will return the letter 'A', the chr(66) function will return the letter 'B', and so on. Here, we have used nested loop conditions in the alphabet pattern and shape-building programs.



Alphabet Pattern Program 1

Suppose someone asks you to print the following pattern using the Python for loop.

A
AB
ABC
ABCD
ABCDE

The solution is as follows. In this alphabetic pattern program, we have used two nested for loops. As we know, 65 is the ASCII code of the letter 'A' and 69 is the ASCII code of the letter 'E'. The outer for loop works in the range(65,70) to print only 5 lines of alphabet. The inner for loop is responsible for printing the alphabets in each row. In the first iteration, it will print the value of chr(j) where j is 65, thus the letter 'A' is printed, and similarly, it will print the whole pattern.

# outer loop for ith rows
for i in range (65,70):
    # inner loop for jth columns
    for j in range(65,i+1):
        print(chr(j),end="")
        
    print()




Alphabet Pattern Program 2

Suppose we have to print repeated alphabet patterns of up to five rows, as shown below.

A
BB
CCC
DDDD
EEEEE

The Python programming solution to the above pattern is as follows. This alphabetic pattern program uses nested for loops. The inner for loop prints chr(i). As a result, only 'A' is printed in the first row, and chr(i) prints 'B' twice in the second row, and so on.

# outer loop for ith rows
for i in range (65,70):
    # inner loop for jth columns
    for j in range(65,i+1):
        print(chr(i),end="")
    print()


Alphabet pattern program 3

The alphabet pattern program of the given pattern is-

A
BC
DEF
GHIJ
KLMNO
PQRSTU
asciichr = 65

# outer loop for ith rows
for i in range(0,6):
    # inner loop for jth columns
    for j in range(0,i+1):
        char = chr(asciichr)
        print(char,end="")
        asciichr += 1
    print()




Alphabet pattern program 4

The alphabet pyramid pattern program is -

        A
      A B C
    A B C D E
  A B C D E F G
A B C D E F G H I
rows=5
# outer loop for ith row
for i in range (1,rows+1):
    asciichr = 65
    for space in range(rows-i): 
       print(' ',end=' ')
    # inner loop for jth columns
    for j in range(1, 2*i):
        char = chr(asciichr)
        print(char+' ' ,end="")
        asciichr += 1

    print()




Alphabet pattern program 5

The alphabet pattern program in shape of right reverse triangle -

A B C D E
F G H I
J K L
M N
O
rows = 5
num = rows
asciichr = 65

# outer loop for ith rows
for i in range(rows, 0, -1):
    # inner loop for jth columns
    for j in range(0, i):
        char = chr(asciichr)
        print(char+' ' ,end="")
        asciichr += 1
    print("\r")


Alphabet pattern program 6

Suppose, someone asks you to print an alphabet pattern program in the reverse shape of 'M' as shown below.

A A A A A A A A A A

B B B B     B B B B

C C C         C C C

D D             D D

E                 E

The code will be as follows -

rows = 6
asciichr = 65
for i in range(0, rows):
    for j in range(rows - 1, i, -1):
        char = chr(asciichr)
        print(char+' ' ,end="")
    for l in range(i):
        print('    ', end='')
    for k in range(i + 1, rows):
        print(char, '', end='')
    print('\n')
    asciichr += 1    




Alphabet pattern program 7

Suppose, someone asks you to print a diamond alphabet pattern made up of 'A' up to a specified number of lines, like this-

        B
      B B B
    B B B B B
  B B B B B B B
B B B B B B B B B
  B B B B B B B
    B B B B B
      B B B
        B

The code will be as follows-

# Upper triangle shape
upper =5
# outer loop for ith row
for i in range (1,upper+1):
    for space in range(upper-i): 
       print(' ',end=' ')
    # inner loop for jth columns
    for j in range(1, 2*i):
        print('B ',end="")

    print()
# Lower triangle shape    
lower = 4
for i in range (lower,0,-1):
    print(' ',end=' ')
    for space in range(lower-i):
        print(' ',end=' ')
    # inner loop for jth columns
    for j in range(1, 2*i):
        print('B ',end="")
    print()


Alphabet pattern program 8

Suppose someone asks you to print an alphabet pattern program as shown below.

ABCDE
ABCD
ABC
AB
A

The code will be as follows -

# outer loop for ith rows
for i in range (70,65,-1):
    # inner loop for jth columns
    for j in range(65,i):
        print(chr(j),end="")
        
    print()




Alphabet pattern program 9

Suppose someone asks you to print an alphabet pattern program as shown below.

AAAAA
BBBBB
CCCCC
DDDDD
EEEEE

The code will be as follows -

# outer loop for ith rows
for i in range (65,70):
    # inner loop for jth columns
    for j in range(65,70):
        print(chr(i),end="")
        
    print()


Alphabet pattern program 10

Suppose someone asks you to print an alphabet pattern program as shown below.

P
PQ
PQR
PQRS
PQRST
PQRSTU

The code will be as follows -

# outer loop for ith rows
for i in range (ord('P'),ord('U')+1):
    # inner loop for jth columns
    for j in range(ord('P'),i+1):
        print(chr(j),end="")
        
    print()




Alphabet pattern program 11

Suppose someone asks you to print an alphabet pattern program as shown below.

      ABCDE
       ABCD
        ABC
         AB
          A

The code will be as follows -

# outer loop for ith rows
for i in range (ord('P'),ord('U')+1):
    # inner loop for jth columns
    for j in range(ord('P'),i+1):
        print(chr(j),end="")
        
    print()


Alphabet pattern program 12

Suppose someone asks you to print an alphabet pattern program in a triangle shape, as shown below.


            o 
          o o o 
        o o o o o 
      o o o o o o o 
    o o o o o o o o o 
  o o o o o o o o o o o 
o o o o o o o o o o o o o 

The code will be as follows -

rows=7
# outer loop for ith rows

for i in range (1,rows+1):
    for space in range(rows-i): 
       print(' ',end=' ')
    # inner loop for jth columns
    for j in range(1, 2*i):
        print('o ',end="")

    print()




Alphabet pattern program 13

Suppose someone asks you to print an alphabet square pattern program as shown below.

A B C D E 
F G H I J 
K L M N O 
P Q R S T 
U V W X Y

The code will be as follows -

# alphabetic square alphabet pattern
size = 5
count = 0

for i in range(size):
    for j in range(size):
        print(chr(65 + count), end=" ")
        count += 1
    print()


Alphabet pattern program 14

Suppose someone asks you to print an alphabet diamond pattern program as shown below.

  A
 ABC
ABCDE
 ABC
  A

The code will be as follows-

# diamond alphabet pattern program
n = 3

# Upper triangle shape
for i in range(n):
    for j in range(n - i - 1):
        print(' ', end='')
    for j in range(2 * i + 1):
        print(chr(65 + j), end='')
    print()

# Lower triangle shape 
for i in range(n - 1):
    for j in range(i + 1):
        print(' ', end='')
    for j in range(2*(n - i - 1) - 1):
        print(chr(65 + j), end='')
    print()


Alphabet pattern program 15

Suppose someone asks you to print the specific string 'PRISKA' as a pattern.

P
PR
PRI
PRIS
PRISK
PRISKA

The code will be as follows -

str= "PRISKA" 
# Outer loop
for i in range(0,7):
    # inner loop
    for j in range(0,i+1):
        print(str[j],end="")
    print()




Alphabet pattern program 16

Suppose someone asks you to print the pattern in decreasing order like this-

A
BA
CBA
DCBA
EDCBA
FEDCBA

The code will be as follows -

# Outer loop
for i in range(65,71):
    # Inner loop
    for j in range(i,64,-1):
        print(chr(j),end="")
    print()


Alphabet pattern program 17

Suppose someone asks you to print an alphabet pattern program in reverse triangle shape as shown below.


D D D D D D D D D 
  D D D D D D D 
    D D D D D 
      D D D 
        D 

The code will be as follows -

rows=5
# outer loop for ith rows
for i in range (rows,0,-1):
    for space in range(rows-i):
        print(' ',end=' ')
        
    # inner loop for jth columns
    for j in range(1, 2*i):
        print('D ',end="")
    print()




Alphabet pattern program 18

Suppose someone asks you to print a hollow triangle alphabet pattern as shown below.


A
AB
A B
A  B
A   B
A    B
ABCDEFG

The code will be as follows-

row = 7
for i in range(1, row+1):
    count = 0
    for j in range(i):
        if j == 0 or j == i-1:
            print(chr(65 + count), end='')
            count += 1
            
        else:
            if i != row:
                print(' ', end='')
            else:
                print(chr(65 + count), end='')
                count += 1
    print()


Alphabet pattern program 19

Suppose someone asks you to print hourglass pattern as shown below.


ABCDEFGHI
 ABCDEFG
  ABCDE
   ABC
    A
   ABC
  ABCDE
ABCDEFG
ABCDEFGHI

The code will be as follows-

# hourglass alphabet pattern
row = 5

# Lower triangle shape    
for i in range(row-1):
    for j in range(i):
        print(' ', end='')
    for k in range(2*(row-i)-1):
        print(chr(65 + k), end='')
    print()

# Upper triangle shape
for i in range(row):
    for j in range(row-i-1):
        print(' ', end='')
    for k in range(2*i+1):
        print(chr(65 + k), end='')
    print()




Related Articles

Remove element from list Python
Pascal triangle pattern in Python
Hollow Diamond Pattern in Python
Reverse pyramid pattern in Python
Vader Sentiment Analysis Python
isalpha Python
Python YouTube Downloader Script
Python project ideas for beginners
Pandas string to datetime
Fillna Pandas Example
Lemmatization nltk
How to generate QR Code in Python using PyQRCode
OpenCV and OCR Python
PHP code to send SMS to mobile from website
Fibonacci Series Program in Python
Python File Handler - Create, Read, Write, Access, Lock File
Python convert XML to JSON
Python convert xml to dict
Python convert dict to xml




Most Popular Development Resources
Retrieve Data From Database Without Page refresh Using AJAX, PHP and Javascript
-----------------
PHP Create Word Document from HTML
-----------------
How to get data from XML file in PHP
-----------------
Hypertext Transfer Protocol Overview
-----------------
PHP code to send email using SMTP
-----------------
Characteristics of a Good Computer Program
-----------------
How to encrypt password in PHP
-----------------
Create Dynamic Pie Chart using Google API, PHP and MySQL
-----------------
PHP MySQL PDO Database Connection and CRUD Operations
-----------------
Splitting MySQL Results Into Two Columns Using PHP
-----------------
Dynamically Add/Delete HTML Table Rows Using Javascript
-----------------
How to add multiple custom markers on google map
-----------------
How to get current directory, filename and code line number in PHP
-----------------
Fibonacci Series Program in PHP
-----------------
Get current visitor\'s location using HTML5 Geolocation API and PHP
-----------------
How to Sort Table Data in PHP and MySQL
-----------------
Simple star rating system using PHP, jQuery and Ajax
-----------------
Submit a form data using PHP, AJAX and Javascript
-----------------
jQuery loop over JSON result after AJAX Success
-----------------
How to generate QR Code in PHP
-----------------
Simple pagination in PHP
-----------------
Recover forgot password using PHP7 and MySQLi
-----------------
PHP MYSQL Advanced Search Feature
-----------------
PHP Server Side Form Validation
-----------------
PHP user registration and login/ logout with secure password encryption
-----------------
jQuery File upload progress bar with file size validation
-----------------
Simple PHP File Cache
-----------------
Simple File Upload Script in PHP
-----------------
Php file based authentication
-----------------
To check whether a year is a leap year or not in php
-----------------
Calculate distance between two locations using PHP
-----------------
PHP User Authentication by IP Address
-----------------
PHP Secure User Registration with Login/logout
-----------------
Simple way to send SMTP mail using Node.js
-----------------
How to print specific part of a web page in javascript
-----------------
Simple Show Hide Menu Navigation
-----------------
Detect Mobile Devices in PHP
-----------------
Polling system using PHP, Ajax and MySql
-----------------
PHP Sending HTML form data to an Email
-----------------
Google Street View API Example
-----------------
Get Visitor\'s location and TimeZone
-----------------
SQL Injection Prevention Techniques
-----------------
Preventing Cross Site Request Forgeries(CSRF) in PHP
-----------------
Driving route directions from source to destination using HTML5 and Javascript
-----------------
Convert MySQL to JSON using PHP
-----------------
Set and Get Cookies in PHP
-----------------
CSS Simple Menu Navigation Bar
-----------------
PHP Programming Error Types
-----------------
Date Timestamp Formats in PHP
-----------------
How to select/deselect all checkboxes using Javascript
-----------------
How to add google map on your website and display address on click marker
-----------------
Write a python program to print all even numbers between 1 to 100
-----------------
How to display PDF file in web page from Database in PHP
-----------------
PHP Getting Document of Remote Address
-----------------
File Upload Validation in PHP
-----------------


Most Popular Blogs
Most in demand programming languages
Best mvc PHP frameworks in 2019
MariaDB vs MySQL
Most in demand NoSQL databases for 2019
Best AI Startups In India
Kotlin : Android App Development Choice
Kotlin vs Java which one is better
Top Android App Development Languages in 2019
Web Robots
Data Science Recruitment of Freshers - 2019


Interview Questions Answers
Basic PHP Interview
Advanced PHP Interview
MySQL Interview
Javascript Interview
HTML Interview
CSS Interview
Programming C Interview
Programming C++ Interview
Java Interview
Computer Networking Interview
NodeJS Interview
ExpressJS Interview
R Interview


Popular Tutorials
PHP Tutorial (Basic & Advance)
MySQL Tutorial & Exercise
MongoDB Tutorial
Python Tutorial & Exercise
Kotlin Tutorial & Exercise
R Programming Tutorial
HTML Tutorial
jQuery Tutorial
NodeJS Tutorial
ExpressJS Tutorial
Theory of Computation Tutorial
Data Structure Tutorial
Javascript Tutorial






Learn Popular Language

listen
listen
listen
listen
listen

Blogs

  • Jan 3

    Stateful vs Stateless

    A Stateful application recalls explicit subtleties of a client like profile, inclinations, and client activities...

  • Dec 29

    Best programming language to learn in 2021

    In this article, we have mentioned the analyzed results of the best programming language for 2021...

  • Dec 20

    How is Python best for mobile app development?

    Python has a set of useful Libraries and Packages that minimize the use of code...

  • July 18

    Learn all about Emoji

    In this article, we have mentioned all about emojis. It's invention, world emoji day, emojicode programming language and much more...

  • Jan 10

    Data Science Recruitment of Freshers

    In this article, we have mentioned about the recruitment of data science. Data Science is a buzz for every technician...

Follow us

  • etutorialspoint facebook
  • etutorialspoint twitter
  • etutorialspoint linkedin
etutorialspoint youtube
About Us      Contact Us


  • eTutorialsPoint©Copyright 2016-2023. All Rights Reserved.