+ 2

Pascal's Triangle

how can i write a code which takse a number (like5) and prints the 5th row of Pascal's Triangle? here is mine but it doesn't work :( import math def combination(n,r): return int((math.factorial(n))/(math.factorial(r))*(math.factorial(n-r))) N=int(input()) for i in range(N): print(combination(N,i),sep=' ')

20th Dec 2017, 6:55 PM
Ali
Ali - avatar
2 Answers
+ 6
#Brackets below the line #N+1 #end instead of sep import math def combination(n,r): return int((math.factorial(n))/((math.factorial(r))*(math.factorial(n-r)))) N=int(input()) for i in range(N+1): print(combination(N,i),end=' ')
21st Dec 2017, 4:13 AM
Louis
Louis - avatar
+ 2
Thank you Louis for correcting the code .I ran it here and it works perfectly. https://code.sololearn.com/ceNYCkCfRWDU/?ref=app A side note to Ali here; the correct internationally recognized name for the binomial coefficient triangle is: KHYAM _ PASCAL triangle , as the Persian mathematician Kayam worked on and descovered the triangle before Pascal. Thanks and Happy Coding!
27th Dec 2017, 3:13 PM
Hamid
Hamid - avatar