Python Pattern programs
Pattern program are mostly for beginners, for improving coding skills.
But also asked in interviews to test logic of candidates.Most asked pattern programs are below
Write a program to print Triangle?
*
* *
* * *
* * * *
* * * * *
for i in range(0,5):
for m in range(0,k):
print(" ",end="")
for j in range(0,i+1):
print("*",end=" ")
k=k-1
print("\r")
Program to print right-angle triangle?
*
* *
* * *
* * * *
* * * * *
for i in range(0,5):
for j in range(0,i+1):
print("*",end=" ")
print("\r")
Output:
*
* *
* * *
* * * *
* * * * *
for i in range(0,5):
for m in range(0,k):
print(" ",end=" ")
for j in range(0,i+1):
print("*",end=" ")
k=k-1
print("\r")
Empty/Hole triangle pattern program?
output:
*
* *
* *
* *
* * * *
c=0
for i in range(0,5):
if(i!=4):
for m in range(0,k):
print(" ",end="")
print("*",end="")
for q in range(0,c):
print(" ",end=" ")
if(c!=0):
print("*",end="")
else:
print(" ",end="")
for i in range(0,4):
print("* ",end=" ")# k=k-1
c=c+1
print("\r")