![]() |
Patterns are a valuable exercise for enhancing logical thinking and coding skills. Using loops in Python, we can create diverse alphabetical patterns like stars, squares, pyramids, and triangles. In this discussion, we’ll explore Python programs for printing these patterns using simple iteration and for loops. Before printing Python patterns, know ASCII: each alphabet corresponds to an ASCII value (e.g., A is 65). Uppercase (A-Z) values range from 65 to 90, and lowercase (a-z) from 97 to 122. Use `chr()` to print an alphabet via its ASCII value, like ‘A’ with ASCII 65. What is an Alphabet Pattern?An Alphabetic pattern is a visual arrangement of alphabets, whether uppercase or lowercase, presented in an aesthetically pleasing manner. These patterns can take on various predefined shapes such as squares, triangles, or even stars. Moreover, the customization of these patterns extends to choosing how they are filled. Print Alphabet Pattern Programs in PythonBelow are the Alphabet pattern programs in Python which we can print in Python. Table of Content
Left Triangle Alphabet Pattern in PythonIn this example, below Python code creates a function, `left_triangle_pattern`, to print a left-angled triangle of uppercase letters based on the specified number of rows. After defining the function, it sets the row count to 7 and calls the function to generate the desired pattern. Python3
Output
A AB ABC ABCD ABCDE ABCDEF ABCDEFG Space Complexity: O(1) Right Triangle Alphabet Pattern in PythonIn this example, below The Python code defines the function `right_triangle_pattern` to print a right-angled triangle of uppercase letters. It uses nested loops to manage line breaks, leading spaces, and character printing. The code sets the row count to 7 and calls the function to generate the pattern. Python3
Output
A AB ABC ABCD ABCDE ABCDEF ABCDEFG Space Complexity: O(1) Hollow Triangle Alphabet Pattern in PythonIn this example, below given Python code defines a function `hollow_left_triangle` to print a hollow left-angled triangle pattern of uppercase letters. It uses nested loops, with the outer loop managing lines and the inner loop controlling character printing, including spaces for the hollow effect. The code sets the number of rows to 7 . Python3
Output
A AB A B A B A B A B ABCDEFG Space Complexity: O(1) Pyramid Alphabet Pattern in PythonIn this example, below Python code defines a function `pyramid_pattern` to print a pyramid pattern of uppercase letters. It utilizes nested loops, with the first loop managing spaces before each line, and the second loop controlling the printing of an odd number of characters. The code then sets the number of rows to 7. Python3
Output
A ABC ABCDE ABCDEFG ABCDEFGHI ABCDEFGHIJK ABCDEFGHIJKLM Space Complexity: O(1) Upside Down Pyramid Alphabet Pattern in PythonIn this example, below Python code defines a function `reverse_pyramid` to print a reversed pyramid pattern of uppercase letters. It uses nested loops, with the first loop managing spaces before each line, and the second loop controlling the printing of an odd number of characters. The code then sets the number of rows to 7 . Python3
Output
ABCDEFGHIJKLM ABCDEFGHIJK ABCDEFGHI ABCDEFG ABCDE ABC A Space Complexity: O(1) Hollow Pyramid Alphabet Pattern in PythonIn this example , below Python code defines a function `hollow_pyramid` to print a hollow pyramid pattern of uppercase letters. It uses nested loops, with the first loop managing spaces before each line, and the second loop controlling the printing of characters. The function includes conditions to print characters only at the start and end of each row, as well as in the last row for the hollow effect. Python3
Output
A A B A B A B A B A B ABCDEFGHIJKLM Space Complexity: O(1) Diamond Alphabet Pattern in PythonIn this example, below Python code defines a function `print_diamond` to print either an upright or a reversed diamond pattern of uppercase letters, based on the `is_upright` parameter. It uses nested loops, with the first loop managing spaces before each line, and the second loop controlling the printing of characters. The code sets the number of rows to 7 and calls the function twice. Python3
Output
A ABC ABCDE ABCDEFG ABCDEFGHI ABCDEFGHIJK ABCDEFGHIJKLM ABCDEFGHIJK ABCDEFGHI ABCDEFG ABCDE ABC A Space Complexity: O(1) Hourglass Alphabet Pattern in PythonIn this example, below Python code defines a function `print_hourglass` to print an hourglass pattern of uppercase letters. It combines a reversed pyramid pattern and an upright pyramid pattern. The function uses nested loops to manage spaces and character printing for both the upper and lower halves of the hourglass. Python3
Output
ABCDEFGHIJKLM ABCDEFGHIJK ABCDEFGHI ABCDEFG ABCDE ABC A ABC ABCDE ABCDEFG ABCDEFGHI ABCDEFGHIJK ABCDEFGHIJKLM Space Complexity: O(1) Square Alphabet Pattern in PythonIn this example , below Python code defines a function `print_square_pattern` to print a square pattern of uppercase letters. It uses nested loops, with the outer loop managing rows and the inner loop controlling the printing of characters. Python3
Output
A A A A A A A B B B B B B B C C C C C C C D D D D D D D E E E E E E E F F F F F F F G G G G G G G Space Complexity: O(1) Heart Alphabet Pattern in PythonIn this example, below Python code defines a function `print_heart_pattern` to print a heart-shaped pattern of uppercase letters. It consists of an upper part and a lower part. The upper part prints characters and spaces in a specific pattern, and the lower part prints characters in a descending order. The code sets the size of the heart based on the rows . Python3
Output
ABCDE ABCDE ABCDEFG ABCDEFG ABCDEFGHI ABCDEFGHI ABCDEFGHIJKLMNOPQRST ABCDEFGHIJKLMNOPQR ABCDEFGHIJKLMNOP ABCDEFGHIJKLMN ABCDEFGHIJKL ABCDEFGHIJ ABCDEFGH ABCDEF ... Space Complexity: O(1) Right Pascal Alphabet Pattern in PythonIn this example, Below Python function `right_pascal_triangle` generates a right-angled Pascal’s Triangle pattern using uppercase letters. It consists of ascending and descending parts, printing spaces and characters in a specific pattern. The code sets the row count to 7 and calls the function to produce the pattern. Python3
Output
A AB ABC ABCD ABCDE ABCDEF ABCDEFG ABCDEF ABCDE ABCD ABC AB A Space Complexity: O(1) Left Pascal Alphabet Pattern in PythonIn this example, below Python code defines a function `left_pascal` to print a left-angled Pascal’s Triangle pattern using uppercase letters. It consists of an ascending part and a descending part, with each part printing characters in a specific pattern. The code sets the number of rows to 7 and calls the function to generate the left-angled Pascal’s Triangle pattern. Python3
Output
A AB ABC ABCD ABCDE ABCDEF ABCDEFG ABCDEF ABCDE ABCD ABC AB A Space Complexity: O(1) ConclusionIn conclusion, exploring alphabet pattern programs in Python has provided a comprehensive insight into the versatility and creative potential of the language. From simple triangular patterns to intricate shapes, these programs serve as a practical and engaging way to enhance one’s understanding of Python’s loop structures and string manipulation capabilities. The ability to customize patterns by adjusting rows, columns, and repetition adds an extra layer of complexity, allowing learners to sharpen their programming skills. Related Article: Programs for Printing Pyramid |
Reffered: https://www.geeksforgeeks.org
Geeks Premier League |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 15 |