I started learning Python and was trying an exercise, but I got struck:
x = 1
y = 1
z = 1
n = 2
list1 = []
list2 = []
for i in range(0, x+1):
for j in range(0, y+1):
for k in range (0, z+1):
if (i+j+k) != n:
list2.clear()
list2.append(i)
list2.append(j)
list2.append(k)
list1.append(list2)
print(list1)
Expected output:
[[0, 0, 0], [0, 0, 1], [0, 1, 0], [1, 0, 0], [1, 1, 1]]
Actual output:
[[1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1]]