Print pattern ‘A’ in Python

Avinash Nethala
programminginpython.com
3 min readJun 6, 2019

Hello everyone! Welcome back to programminginpython.com. I am continuing with this pattern programming series, here I will tell you how to print the pattern of the letter ‘A’.

Also, I will try to display the patterns for all other alphabets later in this series.

Letter A — Pattern Programming — programminginpython.com

Task:

Python program to print the pattern of letter ‘A’

Approach:

  • Read an input integer for asking the size of the letter using input()
  • Check if the entered number is greater than 8,
  • if yes, call the function print_pattern()
  • else, show a message to enter a number which is greater or equal to 8
  • print_pattern()
  • here we only do two things, print star(*) and print space( ), just writing conditions so the pattern of *‘s and ‘s will display the pattern ‘A’
  • following are 3 conditions for printing *’s
    We have 2 loops, outer loop() for row’s and inner loop for columns.
     # Outer for loop
for i in range(n):

# Inner for loop
for j in range((n // 2) + 1):
  1. every line — at the start and end

(j == 0 or j == n //2) and i != 0

2. middle line — the whole line

i == n // 2

3. first line — whole line except first and last row

i == 0 and j != 0 and j != n // 2
  • print in remaining all cases.

Program:

__author__ = 'Avinash'# Python3 program to print alphabet A pattern# Function to display alphabet pattern 
def print_pattern(n):

# Outer for loop for number of lines(rows)
for i in range(n):

# Inner for loop for printing *'s and &nbsp's(columns)
for j in range((n // 2) + 1):

# prints two column lines
if ((j == 0 or j == n //2) and i != 0 or

# print first line of alphabet
i == 0 and j != 0 and j != n // 2 or

# prints middle line
i == n // 2):
print("*", end = "")
else:
print(" ", end = "")

print()
# Size of the letter
num = int(input("Enter the size: \t "))
if num > 7:
print_pattern(num)
else:
print("Enter a size minumin of 8")

Output:

Letter A — Pattern Programming — programminginpython.com

That’s it for this post guys, also feel free to check other programs on patterns here or find some programs on algorithms here.

--

--