I am trying to print out pascals triangle based on a user input, and it works, but it prints out the data in a list, and when i try and convert the lists into a string so I can format it, it messes with the code and it changes the list in the loop.
Here is my code below, right now it will calculate up to the 8th row, and then it will print out all of the values, I dont want it to print out all the values at the end and I want to remove all of the brackets.
Can anyone tell me what Im doing wrong?
def triangle(n): if n == 0: return  elif n == 1: return [] else: new_row =  result = triangle(n-1) last_row = result[-1] print(last_row) for i in range(len(last_row)-1): new_row.append(last_row[i] + last_row[i+1]) new_row +=  result.append(new_row) a=result[:] print(a) print(triangle(9))
Any constructive thoughts would be appreciated, Thanks.