Pascal Triangle


# Number Triangles

# Pascals Triangle

"""

"""

# Factorial Function 


def fact(Num):

if(Num==0):

return 1

else:

return Num*fact(Num-1)



# Read Number of lines 

N = int(input("Enter number of Lines : "))


print("Pascal Triangle : ")


for n in range(0,N,1):

Nr = fact(n)

        # For Alignment

print("   "*(N-n),end="")

for k in range(0,n+1,1):

term = (int)(Nr/(fact(k)*fact(n-k)))

print(str(term).center(6), end="")

print()




# Output


> python PascalTriangle.py

Enter number of Lines : 10

Pascal Triangle :




Formula for calculating elements in Pascal Triangle




No comments:

Post a Comment

Don't be a silent reader...
Leave your comments...

Anu