- To print sideway reverse triangle pattern using *
User Input: 3
Output:
* * * * * * * * *
columns=int(input("Enter number of columns : "))
k=trows=2*columns-1
for i in range(trows,0,-1):
for j in range(1,trows+1):
if(j<k):
print(" ", end="")
else:
print("* ", end="")
if(i<=columns):
k+=1
else:
k-=1
print("")
Enter number of columns: 4 * * * * * * * * * * * * * * * *Program
Main Logic :
trows=2*columns-1 #trows : total rows to print
k=trows #Used to trigger decreasing order of *
for i in range(trows,0,-1):
for j in range(1,trows+1):
if(j<k):
print(" ", end="")
else:
print("* ", end="")
#Check for position change at which triangle * value to decrease
if(i<=columns):
k+=1
else:
k-=1
print("")
You can print any thing in this pattern, just replace your value with *