Program to Print Pascal’s Triangle Without using a Function || Python Program

preview_player
Показать описание
firstly we will take input from the user to enter the number of rows to present in Pascal’s Triangle. Then, we will create a list after that, we will implement a ‘nested for loop’ to make the pattern of Pascal’s triangle in Python Programming.
Code:
#python program to print pascal triangle

n= int(input("Enter the number of rows: "))
l = []

for i in range(n):
l[i].append(1)
for j in range(1, i):
l[i].append(l[i-1][j-1]+l[i-1][j])
if (n != 0):
l[i].append(1)

for i in range(n):
print(" "*(n-i), end=" ", sep=" ")
for j in range(0, i+1):
print("{0:6}".format(l[i][j]), end=" ", sep=" ")
print()

#pascaltriangleInpython #patternprograminpython #pythonbeginners
Рекомендации по теме