As the title says, I have a problem using list comprehension for creating the Pascal Triangle.
n = int(input())
a = []
a = [[1 if j > 0 and j < n-1 else a[i-1][j] + a[i-1][j-1] for j in range(i)] for i in range(n)]
print(*a, sep = '\n')
I get the following error: (https://i.stack.imgur.com/dd6w5.png)
I don't understand where the index gets out of range and how I can fix it. Thank you.
To compute pascal triangle using list comprehension, you can use
math.factorial:Prints: