Explore

Close
Pattern Programs Share

Python Program To Print Alphabet Pattern D

Python Program To Print Alphabet Pattern D

Looking for a python program to print alphabet pattern ‘D’ then you are at the right place, today I will show you how to create a python program to print the alphabet pattern D so without wasting time let’s start.

To create this program we will use for loops and if else statements, so you need to know them in order to understand how this program works.

Python Program To Print Alphabet Pattern ‘D’ 


pattern = ""    
for row in range(0,7):    
    for col in range(0,7):     
        if (col == 1 or ((row == 0 or row == 6) and (col > 1 and col < 5)) or (col == 5 and row != 0 and row != 6)):  
            pattern = pattern + "#"    
        else:      
            pattern = pattern + " "    
    pattern = pattern + "\n"    
print(pattern)    

Above is the python program to print alphabet pattern D. Now to run this program you need to have python installed on your computer, If you don’t have then follow this guide: Install and setup python on your computer.

The Complete Python Programming Boo...
The Complete Python Programming Bootcamp

To run this python program, follow the below steps:

  • Create a new folder for this python project.
  • Open it in a code editor of your choice.
  • Create a python file with an ending .py extension.
  • Copy the above code and paste it in your file.
  • Open a terminal or CMD at folder location
  • And type this command python filename.py (Name of your file).

After running this program you will see the alphabet D printed like below output.


 ####  
 #   # 
 #   # 
 #   # 
 #   # 
 #   # 
 ####  

Don’t want to create all the files and folders then you can run this program now using this online python compiler it is fast and easy.

Summary

This was the python program to print the alphabet pattern 'D'. I hope you found this tutorial helpful and useful. Do share this tutorial with your friends who might be interested in this program.

Here are some more python pattern programs for you:

I hope you found what you were looking for from this tutorial, and if you want more python programs and tutorials like this, do join our Telegram channel for future updates.

Thanks for reading, have a nice day 🙂