Above all else, kindly try not to utilize names of built-in functions as variable names (for your situation, list; I've transformed it to l). Besides that, putting a label as you referenced is basically referring to the iteration of the peripheral loop you have. This after code ought to carry on as expected:
x = int(input("Enter the desired height. "))
l = [1]
for i in range(x):
# Modified v
print("Row", i + 1, l)
newlist = []
newlist.append(l[0])
for i in range(len(l) - 1):
newlist.append(l[i] + l[i+1])
newlist.append(l[-1])
l = newlist
Sample run:
Enter the desired height. 4
Row 1 [1]
Row 2 [1, 1]
Row 3 [1, 2, 1]
Row 4 [1, 3, 3, 1]
Looking for a good python tutorial course? Join the python certification course and get certified.
For more details, do check out the below video tutorial...