Write a python program, which asks user to enter value for number of line and then according to input following pattern, should be displayed. - Pratik Ghelani

Pratik Ghelani

Breaking

Sunday, May 10, 2020

Write a python program, which asks user to enter value for number of line and then according to input following pattern, should be displayed.


Input:-


n=int(input("Enter number of rows: "))
a=[]
for i in range(n):
    a.append([])
    a[i].append(1)
    for j in range(1,i):
        a[i].append(a[i-1][j-1]+a[i-1][j])
    if(n!=0):
        a[i].append(1)
for i in range(n):
    print("   "*(n-i),end=" ",sep=" ")
    for j in range(0,i+1):
        print('{0:6}'.format(a[i][j]),end=" ",sep=" ")
    print()



Output:-


No comments:

Post a Comment