TechBeamersTechBeamers
  • Learn ProgrammingLearn Programming
    • Python Programming
      • Python Basic
      • Python OOP
      • Python Pandas
      • Python PIP
      • Python Advanced
      • Python Selenium
    • Python Examples
    • Selenium Tutorials
      • Selenium with Java
      • Selenium with Python
    • Software Testing Tutorials
    • Java Programming
      • Java Basic
      • Java Flow Control
      • Java OOP
    • C Programming
    • Linux Commands
    • MySQL Commands
    • Agile in Software
    • AngularJS Guides
    • Android Tutorials
  • Interview PrepInterview Prep
    • SQL Interview Questions
    • Testing Interview Q&A
    • Python Interview Q&A
    • Selenium Interview Q&A
    • C Sharp Interview Q&A
    • PHP Interview Questions
    • Java Interview Questions
    • Web Development Q&A
  • Self AssessmentSelf Assessment
    • Python Test
    • Java Online Test
    • Selenium Quiz
    • Testing Quiz
    • HTML CSS Quiz
    • Shell Script Test
    • C/C++ Coding Test
Search
  • Python Multiline String
  • Python Multiline Comment
  • Python Iterate String
  • Python Dictionary
  • Python Lists
  • Python List Contains
  • Page Object Model
  • TestNG Annotations
  • Python Function Quiz
  • Python String Quiz
  • Python OOP Test
  • Java Spring Test
  • Java Collection Quiz
  • JavaScript Skill Test
  • Selenium Skill Test
  • Selenium Python Quiz
  • Shell Scripting Test
  • Latest Python Q&A
  • CSharp Coding Q&A
  • SQL Query Question
  • Top Selenium Q&A
  • Top QA Questions
  • Latest Testing Q&A
  • REST API Questions
  • Linux Interview Q&A
  • Shell Script Questions
© 2024 TechBeamers. All Rights Reserved.
Reading: Print Alphabet Pattern “A” Using Range()
Font ResizerAa
TechBeamersTechBeamers
Font ResizerAa
  • Python
  • SQL
  • C
  • Java
  • Testing
  • Selenium
  • Agile Concepts Simplified
  • Linux
  • MySQL
  • Python Quizzes
  • Java Quiz
  • Testing Quiz
  • Shell Script Quiz
  • WebDev Interview
  • Python Basic
  • Python Examples
  • Python Advanced
  • Python OOP
  • Python Selenium
  • General Tech
Search
  • Programming Tutorials
    • Python Tutorial
    • Python Examples
    • Java Tutorial
    • C Tutorial
    • MySQL Tutorial
    • Selenium Tutorial
    • Testing Tutorial
  • Top Interview Q&A
    • SQL Interview
    • Web Dev Interview
  • Best Coding Quiz
    • Python Quizzes
    • Java Quiz
    • Testing Quiz
    • ShellScript Quiz
Follow US
© 2024 TechBeamers. All Rights Reserved.
Python ExamplesPython Tutorials

Print Alphabet Pattern “A” Using Range()

Last updated: Nov 06, 2023 10:18 pm
By Meenakshi Agarwal
Share
4 Min Read
Print alphabet pattern A using range
Print alphabet pattern A using range
SHARE

This Python program explains a step-by-step process to print the alphabet pattern “A” using the Python range function. It includes a working sample for help.

Contents
Alphabet pattern “A” program requirementTechnique-1Technique-2

Range() to Print Alphabet Pattern “A”

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

Alphabet pattern “A” program requirement

Our objective for this exercise is to produce an Alphabet “A” shape like the one given below. The pattern uses the star symbol and prints across nine lines.

Must Read: How to Print Patterns in Python – 20 Examples

You need to develop a program that takes a number and prints, using asterisks, a full “A” of the given length. For Example, if the line size is 7 or 11, the code should print:

# Test input: 7
 ** 
*  *
*  *
****
*  *
*  *
*  *
# Test input: 11
 ***** 
*     *
*     *
*     *
*     *
*     *
*******
*     *
*     *
*     *
*     *
*     *

Also, you must make use of the Python range method for traversing through the loop.

Technique-1

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

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

# Intentionally printing a blank line
print()

# Test Case-2
print_alpha_A(11)

Technique-2

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.

"""
Program desc:
 This is a Python program to print A shape using
 Python string repeat feature in one loop
"""

""" Function to print alphabet A pattern in one loop """
def print_alphabet_pattern(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(7)

# Intentionally printing a blank line
print()

# Test Case-2
print_alphabet_pattern(11)

After executing the above code, you will see that it is producing the following “A” shape.

       *  *
      *    *
     *      *
    **********
   *          *
  *            *
 *              *

           *  *
          *    *
         *      *
        *        *
       *          *
      **************
     *              *
    *                *
   *                  *
  *                    *
 *                      *

You can now take clues from the above code samples and try some by yourself. It will make you think differently and help to build a logic of your own.

You Might Also Like

How to Connect to PostgreSQL in Python

Generate Random IP Address (IPv4/IPv6) in Python

Python Remove Elements from a List

How to Use Extent Report in Python

10 Python Tricky Coding Exercises

Meenakshi Agarwal Avatar
By Meenakshi Agarwal
Follow:
Hi, I'm Meenakshi Agarwal. I have a Bachelor's degree in Computer Science and a Master's degree in Computer Applications. After spending over a decade in large MNCs, I gained extensive experience in programming, coding, software development, testing, and automation. Now, I share my knowledge through tutorials, quizzes, and interview questions on Python, Java, Selenium, SQL, and C# on my blog, TechBeamers.com.
Previous Article Agile Scrum Questions for Interview Prep More Agile Scrum Questions for Interviews
Next Article Convert Python list to string with examples Convert a List to String in Python

Popular Tutorials

SQL Interview Questions List
50 SQL Practice Questions for Good Results in Interview
SQL Interview Nov 01, 2016
Demo Websites You Need to Practice Selenium
7 Sites to Practice Selenium for Free in 2024
Selenium Tutorial Feb 08, 2016
SQL Exercises with Sample Table and Demo Data
SQL Exercises – Complex Queries
SQL Interview May 10, 2020
Java Coding Questions for Software Testers
15 Java Coding Questions for Testers
Selenium Tutorial Jun 17, 2016
30 Quick Python Programming Questions On List, Tuple & Dictionary
30 Python Programming Questions On List, Tuple, and Dictionary
Python Basic Python Tutorials Oct 07, 2016
//
Our tutorials are written by real people who’ve put in the time to research and test thoroughly. Whether you’re a beginner or a pro, our tutorials will guide you through everything you need to learn a programming language.

Top Coding Tips

  • PYTHON TIPS
  • PANDAS TIPSNew
  • DATA ANALYSIS TIPS
  • SELENIUM TIPS
  • C CODING TIPS
  • GDB DEBUG TIPS
  • SQL TIPS & TRICKS

Top Tutorials

  • PYTHON TUTORIAL FOR BEGINNERS
  • SELENIUM WEBDRIVER TUTORIAL
  • SELENIUM PYTHON TUTORIAL
  • SELENIUM DEMO WEBSITESHot
  • TESTNG TUTORIALS FOR BEGINNERS
  • PYTHON MULTITHREADING TUTORIAL
  • JAVA MULTITHREADING TUTORIAL

Sign Up for Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

Loading
TechBeamersTechBeamers
Follow US
© 2024 TechBeamers. All Rights Reserved.
  • About
  • Contact
  • Disclaimer
  • Privacy Policy
  • Terms of Use
TechBeamers Newsletter - Subscribe for Latest Updates
Join Us!

Subscribe to our newsletter and never miss the latest tech tutorials, quizzes, and tips.

Loading
Zero spam, Unsubscribe at any time.
x