#! /usr/bin/env python """ pascal.py is program which calculates the binomial coefficient via a user defined function. The program generates Pascal's triangle out to 20 lines. In combinatorics of n elements disregarding their order, the binomial coefficient (n,k) gives the number of ways to choose k elements (i.e. n choose k). Given 0 elements there is only the one way to chose 0 elements (0,0) =1 Given 1 element there is 1 way to choose 0 elements (1,0) & 1 way to choose 1 element (1,1), ... Paul Eugenio PHZ4151C Jan 25, 2019 """ # program header code from __future__ import division, print_function from math import factorial def binomial(n, k): """ Binomial coefficient (n k) = n!/(k!(n-k)! """ return ( factorial(n) // (factorial(k)*factorial(n-k)) ) # constants TRIANGLE_SIZE = 20 # # main # # print out pascal's triangle for n in range(TRIANGLE_SIZE): for k in range(0, n+1): print(binomial(n, k), end=' ') print(" ")