+ 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=' ')
2 Antworten
+ 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=' ')
+ 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!