I'm writing a code for homework, it needs t o output the values for pascal's triangle, but not in a triangle. for instance I input
pascalLine(2) it outputs:
[1,2,1] and for:
pascalLine(4) it outputs:
[1,4,6,4,1] I currently have this code and I believe it is far from complete, because It outputs a triangle.
def pascalLine(n): for rownum in range (n): newValue=1 PrintingList = list() for iteration in range (rownum): newValue = newValue * ( rownum-iteration ) * 1 / ( iteration + 1 ) PrintingList.append(int(newValue)) print(PrintingList) print()
[1,2,1]and[1,4,6,4,1]the OP gives are examples of the desired output. I.e. the function should return the nth row of Pascal's triangle as a list.