In this tutorial, We can Create alphabetical patterns usingĀ Python. They can be done using loops and conditionals.Drawing alphabetical patterns in Python can be accomplished in various ways, depending on the specific pattern you want to create.
Here we can learn simply logic to create various patterns.You might be checking for the input tricks but by this simple logic we can print all the alphabets in different drawing patterns . We can also customize them by modifying the pattern value.
All the alphabetical pattern drawing using Python
Learn how to draw all alphabetical pattern with simple examples, Which you might be searching with your sets of requirements .
These the points which explains about the code given below.
- Here we use ASCII value to convert into the character.
- It initiates a loop where ‘
i'
iterates over the ASCII values from 65 (which corresponds to ‘A’) to 90 (which corresponds to ‘Z’ inclusive).Another initiates a loop where ‘j'
iterates over the ASCII values from 65 to ‘i'
(inclusive). This loop is responsible for printing the alphabet characters in each row. - The ‘
end=" "'
parameter specifies that a space should be printed after each character instead of a newline.
Code:
def print_alphabet_pattern(pattern): if pattern == 1: print("Alphabet Pattern 1:") for i in range(65, 91): for j in range(65, i + 1): print(chr(j), end=" ") print() elif pattern == 2: print("Alphabet Pattern 2:") for i in range(65, 91): for j in range(65, i + 1): print(chr(i), end=" ") print() elif pattern == 3: print("Alphabet Pattern 3:") for i in range(65, 91): for j in range(65, i + 1): print(chr(j), end=" ") print() for i in range(89, 64, -1): for j in range(65, i + 1): print(chr(j), end=" ") print() elif pattern == 4: print("Alphabet Pattern 4:") for i in range(65, 91): for j in range(65, i + 1): print(chr(i), end=" ") print() for i in range(89, 64, -1): for j in range(65, i + 1): print(chr(i), end=" ") print() else: print("Invalid pattern number. Please choose a number between 1 and 4.") print_alphabet_pattern(1)
If you run this code you will see the output like below,
Output :
Alphabet Pattern 1: A A B A B C A B C D A B C D E A B C D E F A B C D E F G A B C D E F G H A B C D E F G H I A B C D E F G H I J A B C D E F G H I J K A B C D E F G H I J K L A B C D E F G H I J K L M A B C D E F G H I J K L M N A B C D E F G H I J K L M N O A B C D E F G H I J K L M N O P A B C D E F G H I J K L M N O P Q A B C D E F G H I J K L M N O P Q R A B C D E F G H I J K L M N O P Q R S A B C D E F G H I J K L M N O P Q R S T A B C D E F G H I J K L M N O P Q R S T U A B C D E F G H I J K L M N O P Q R S T U V A B C D E F G H I J K L M N O P Q R S T U V W A B C D E F G H I J K L M N O P Q R S T U V W X A B C D E F G H I J K L M N O P Q R S T U V W X Y A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Later, if you want to print a different pattern, just change the argument passed to the print_alphabet_pattern()
function to the desired pattern number (1, 2, 3, or 4).