[ Web Proxy ]
URL:
Viewing: https://www.programminginpython.com/python-program-print-pattern-letter-b/#comments [Back]  [Original]

Python Program to print pattern of letter B - Programming In Python
Skip to content
Home Python Program to print pattern of letter B

Python Program to print pattern of letter B

Python Program to print pattern of letter B [Python Program to print pattern of letter B] Python Program to print pattern of letter B

Hello everyone! Welcome back toprogramminginpython.com. I am continuing with this pattern programming series, here I will tell you how to print the pattern of the letter B. In the previous tutorial, I have shown you the pattern for the letter A.

You can also watch the video on YouTube here.

Program on Github

Task:

Python program to print the pattern of letter B

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 that 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 B
    • following are 3 conditions for printing *s
      We have 2 loops, an outer loop() for rows and an inner loop for columns.

      # Outer for loop
      for i in range(n):  
          # Inner for loop 
          for j in range(n + 1):
        1. the first line of alphabet
          i == 0 and j != 0 and j != n
        2. middle line the whole line
          i == n // 2
        3. last line the whole line
          i == n - 1
    • print `` in remaining all cases.

Program on GitHub

Python Program:

__author__ = 'Avinash'

# Python3 program to print alphabet B 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 logic execution
        for j in range(n + 1):
            # prints two column lines
            if ((j == 0 or j == n) or
                    # print first line of alphabet
                    i == 0 and j != 0 and j != n or
                    # prints last line
                    i == n - 1 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 minimum of 8")

Program on GitHub

Print Pattern B Code Visualization

Output:

Python Program to print pattern of Letter B [Python Program to print pattern of Letter B]Python Program to print pattern of Letter B

Thats it for this post guys, also feel free to check other programs on patternshereor find some programs on algorithmshere.

Course Suggestion

Machine Learning is everywhere! So I strongly suggest you take the course below.
Course: Machine Learning Adv: Support Vector Machines (SVM) Python

 

Online Python Compiler

Tagged: for loop letter patterns pattern B pattern programming

Post navigation

Leave a Reply Cancel reply

author:
email:
url:
comment:
ak_hp_textarea:

Programming In Python 2026. Powered By BlazeThemes.

Web Proxy Viewer  |  New URL  |  Original Page