Patterns can be printed in python using simple for loops. The first outer loop is used to handle a number of rows and the Inner nested loop is used to handle the number of columns. Manipulating the print statements, different number patterns, alphabet patterns, or star patterns can be printed.
Some of the Patterns are shown in this article.
Some of the Patterns are shown in this article.
*
**
***
****
*****
code 👇:
n = int(input('enter the number'))
for i in range(1,n+1):
print('*'*i,end=' ')
print()
* ** *** *** ** *
code 👇:
n = int(input('enter the number')) for i in range(1,n+1): print('*'*i,end=' ') print() for j in range(n,0, -1): print('*' * j, end = ' ') print()
* * * * * *
code 👇:
n = int(input('enter the number')) k = 2*n -2 for i in range(0, n): for j in range(0, k): print(end=" ") k = k - 2 for j in range(0, i + 1): print("* ", end="") print("")
* * * * * * * * * *
code 👇:
n = int(input('enter the number')) k = 2*n -2 for i in range(0, n): for j in range(0, k): print(end=" ") k = k - 1 for j in range(0, i + 1): print("* ", end="") print("")
Find more patterns at my github.* * * * * * * * * * * * * * * * * * * * * * * * *
code 👇:
n = int(input('enter the number')) k = 2*n -2 for i in range(0, n): for j in range(0, k): print(end=" ") k = k - 1 for j in range(0, i + 1): print("* ", end="") print("") k = n -2 for i in range(n,-1,-1): for j in range(k,0,-1): print(end=" ") k = k + 1 for j in range(0,i+1): print("* ", end="") print("")
Happy Learning :)
0 Comments