In this shot, we will discuss how to generate a hollow equilateral triangle in Python.
We can print a plethora of patterns using Python. The only prerequisite to do this is a good understanding of how loops work in Python. Here, we will be using simple
for loops to generate a hollow equilateral triangle using numbers.
A triangle is said to be equilateral if it has all three sides of the same length. To create a hollow equilateral triangle with numbers using Python programming, we will be using two
Let’s look at the below code snippet.
def hollow_triangle(n): # Outer loop for rows for i in range(1,n+1): # Inner loop for columns for j in range(1,2*n): # Conditions for creating the pattern if i==n or i+j==n+1 or j-i==n-1: print(i, end=" ") else: print(end=" ") print() hollow_triangle(5)
forloop to handle the number of rows.
forloop to handle the number of columns.
print()to move to the next line.
hollow_triangle, which takes the row size as an argument.
View all Courses