there is many ways to draw text pattern in python but I want to draw text pattern like triangle by using of center function in python the sample output could be like this:
CodePudding user response:
def numpat(n):num = 1for i in range(0, n):num=1for j in range(0, i 1):num = num 1print("\r")n = 5numpat(n)
Use this the output will be first triangle in second line.
CodePudding user response:
def triangle(n):
k = n - 1
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("\r")
n = 5
triangle(n)