Ans.
n=5
sp = 2 * n - 2
for i in range(0, n):
for j in range(0, sp):
print(end=" ")
sp = sp - 2
for j in range(0, i + 1):
print("* ", end = "")
print()
Ans.
num = 5
for i in range (1, num + 1):
sp = (num - i) * " "
print(sp, end = " ")
for k in range(i, 1, -1):
print("*", end = " ")
for j in range(1, i + 1):
print("*", end = " ")
print()
Ans i)
n = 3
for i in range (1, n + 1):
sp = (n - i) * " "
sym = (2 * i - 1) * "*"
print(sp, sym)
for j in range(n - 1, 0, -1):
sp = (n - j) * " "
sym = (2 * j - 1)* "*"
print(sp, sym)
ii)
num = 5
for i in range (1, num + 1):
sp = (num - i) * " "
print(sp, end = " ")
for k in range(i, 1, -1):
print(k, end = " ")
for j in range(1, i + 1):
print(j, end = " ")
print()
iii)
str = "123456"
for i in (str):
print(" " * int(i) + str[0 : len(str) - int(i)])
OR
num = 5
for i in range (num, 0, -1):
sp = (num - i) * " "
print(sp, end=" ")
for k in range(1, i + 1):
print(k, end=" ")
print()
iv)
num = 3
k = 0
for i in range (1, num + 1):
sp = (num - i)*" "
print(sp, end=' ')
while (k != (2 * i - 1)) :
if (k == 0 or k == 2 * i - 2) :
print("*", end= "")
else :
print(" ", end = "")
k = k + 1
k = 0
print( )
for j in range (num - 1, 0, -1):
sp = (num - j) * " "
print(sp, end=" ")
k = (2 * j - 1)
while (k > 0) :
if (k==1 or k == 2 * j - 1): print("*",end="")
else:
print(" ",end="")
k = k - 1
print( )
Ans.
num = 5
for i in range (1, num + 1):
sp = (num - i) * " "
print(sp, end = " ")
for k in range(i, 1, -1):
print(i, end = " ")
for j in range(1, i + 1):
print(i, end = " ")
print()
Pattern Programs in Python
Disclaimer : I tried to give you the correct code of ” Pattern Programs in Python ” , but if you feel that there is/are mistakes in ” Pattern Programs in Python ” given above, you can directly contact me at csiplearninghub@gmail.com. Book and Study material available on CBSE official website are used as a reference to create above “Pattern Programs in Python “.