Python Program to Print Alphabet Pattern A using Range() – My programming school

Alphabet Pattern Programs in Python:

Alphabet pattern programs in python to Print Alphabet Pattern A utilizing Range(). This python program clarifies a bit-by-bit cycle to print the alphabet pattern “A”utilizing the Python range function. It’s anything but a functioning example of help.

alphabet pattern

We have shown multiple ways to print the alphabet pattern“A” in this post. Please read and evaluate them one by one.

Print Alphabet Pattern A in Python

Alphabet pattern programs in python to Print Alphabet Pattern A utilizing Range(). This python program clarifies a bit-by-bit interaction to print the alphabet pattern”A”utilizing the Python range function. It’s anything but a functioning sample the objective of this activity is to create an Alphabet “A” shape like the one given beneath. The pattern is utilizing the star image and prints across nine lines.

You need to foster a program that takes a number and prints, utilizing bullets, an entire “A” of the given length. For Example, if the line size is 7 or 11, the code ought to print:e for help.

#Note:You can test program by providing-different input #value
#Test input:7
** * * * * **** * * * * * * #Test input:11
***** * * * * * * * * * * ******* * * * * * * * * * *

Also, you must make utilization of the Python range way for traversing through the loop.

1) Python Pattern Programs Alphabet A

Here, we have created a function and used inner loops with the range() function to print the wanted “A” pattern.

"""
Description:
 Python3.x program to print alphabet pattern"A"
"""
"""Function to display alphabet pattern"""
def print_alpha_pattern_A(size): 
  
    #Main for-loop for specified lines 
    for i in range(size): 
  
        #Child for loop for drawing the pattern
        for j in range((size//2)+1): 
  
            #Now,printing two vertical-lines 
            if ((j==0 or j==size//2) and i !=0 or
  
                #Printing first vetical-line to form A
                i==0 and j!= 0 and j!= size//2 or
  
                #Drawing the center line
                i==size//2): 
                print("*",end="") 
            else: 
                print(" ",end="") 
          
        print() 
      
  
#Test Case-1
print_alpha_pattern_A(7)

#Intentionally printing a blank-line
print()

#Test Case-2
print_alpha_pattern_A(11)

Output:

Python Pattern Programs Alphabet

2) How to Print Alphabet Pattern A in Python

In this technique, we’ll use the Python string property to repeat itself by a number specified along with the multiplication symbol. It is also interesting to know for you that we are using one loop to print the alphabet “A” pattern.

"""
description:
 This is a Python program to print A pattern using
 Python string repeat feature in one-loop
"""

"""Function to display alphabet A pattern in one loop"""
def print_alphabet_pattern_A(lines):
    temp= 1
    for iter in range(lines):
        if lines-iter-1== lines//2:
            print((lines-iter) * ' '+1* '*'+2*(temp+iter) * '*'+1 * '*')
        else:
            print((lines-iter) * ' ' + 1 * '*'+2*(temp+iter) * ' ' + 1 * '*')

#Test Case-1
print_alphabet_pattern_A(7)

#Intentionally printing a blank-line
print()

#Test Case-2
print_alphabet_pattern_A(11)

Output:

After performing the above source code, you will see that it is producing the following “A” pattern.

How to Print Alphabet Pattern in Python

You would now be able to take signs from the above code tests and attempt some without anyone else. It will make you think diversely and help to fabricate your very own rationale.

Recommended Post:

Pramod Kumar Yadav is from Janakpur Dham, Nepal. He was born on December 23, 1994, and has one elder brother and two elder sisters. He completed his education at various schools and colleges in Nepal and completed a degree in Computer Science Engineering from MITS in Andhra Pradesh, India. Pramod has worked as the owner of RC Educational Foundation Pvt Ltd, a teacher, and an Educational Consultant, and is currently working as an Engineer and Digital Marketer.



Leave a Comment