Python Program To Print Hollow Triangle Pattern
Want to know how to print hollow triangle pattern in python, then you are at the right place today in this tutorial. I will show you the python program to print hollow triangle pattern, so follow this tutorial till the end.
Printing patterns in python is fun and very interesting. You must have created python programs to print diamond and other shapes but today I will show you how to print a hollow triangle pattern in python.
We will use for loops for creating this pattern so no external python library is needed, just follow this tutorial till the end.
Python Code To Print Hollow Triangle Pattern
row = 10 for i in range(row): for j in range(row-i): print(' ', end='') for j in range(2*i+1): if j==0 or j==2*i or i==row-1: print('*',end='') else: print(' ', end='') print()
Above is the python program to print hollow triangle pattern. 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.
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 a hollow triangle pattern 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.
This was the python program to print hollow triangle pattern. 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 drawing tutorials for you:
- Python Program To Print Hollow Right Angled Triangle Pattern.
- Python Program To Convert Miles To Feet.
- Python Program To Convert Rupee To Paise.
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 🙂