You are given three integers and representing the dimensions of a cuboid
Answers
Answered by
0
X, Y and Z are the three coordinates of a cuboid.
Now X=1,Y=1, Z=1 and N=2.
I have to generate a list of all possible coordinates on a 3D grid where the sum of Xi + Yi + Zi is not equal to N. If X=2, the possible values of Xi can be 0, 1 and 2. The same applies to Y and Z.
I have written this below code so far, and it is giving the output as :
[[0, 0, 0]]
however the expected output is
[[0, 0, 0], [0, 0, 1], [0, 1, 0], [1, 0, 0], [1, 1, 1]]
Below is my code, what is going wrong in my code?
[[x,y,z] for x in range(X) for y in range(Y) for z in range(Z) if x+y+z != N]
Now X=1,Y=1, Z=1 and N=2.
I have to generate a list of all possible coordinates on a 3D grid where the sum of Xi + Yi + Zi is not equal to N. If X=2, the possible values of Xi can be 0, 1 and 2. The same applies to Y and Z.
I have written this below code so far, and it is giving the output as :
[[0, 0, 0]]
however the expected output is
[[0, 0, 0], [0, 0, 1], [0, 1, 0], [1, 0, 0], [1, 1, 1]]
Below is my code, what is going wrong in my code?
[[x,y,z] for x in range(X) for y in range(Y) for z in range(Z) if x+y+z != N]
Answered by
0
Answer:
if __name__ == '__main__':
x = int(raw_input())
y = int(raw_input())
z = int(raw_input())
n = int(raw_input())
l=[]
for i in range(x+1):
for j in range(y+1):
for k in range(z+1):
if((i+j+k)!=n):
l.append([i,j,k])
k+=1
j+=1
i+=1
print(l)
Step-by-step explanation:
the range is supposed to be x+1 ,y+1,z+1
Because range() function will provide numbers from 0 to n-1
Similar questions