Good, so I have been working on this for a long time, and I canβt get it. Our task was to make a triangle and the center of Pascal, and all this is a good thing ... But I can not understand it.
def factorial(n): if (n <= 1): return 1 else: return n * factorial(n-1) def combination(n, k): return int (factorial(n) / (factorial(k) * factorial(nk))) def pascal_row(row): answer = "" for entry in range(row+1): answer = answer + " " + str(combination(row, entry)) print answer def pascal_triangle(rows): for row in range(rows): pascal_row(row) pascal_triangle(10)
I know that if I make the last line, which is 9 and subtract the current line, and then multiply by three, it will give me the correct spacing for each line. I'm just not sure how to include this in code? If you could help me, that would be fantastic! Thanks for the help in advance.
source share