You are viewing a single comment's thread. Return to all comments →
cuboid = 
results = [cuboid.append([x, y, z]) for x in range(X+1) for y in range(Y+1) for z in range(Z+1) if x + y + z != N]
Less lines, more Pythonic
That's really great :)
print ([[a,b,c] for a in range(int(input())+1) for b in range(int(input())+1) for c in range(int(input())+1) if a+b+c!=int(input())])
why does this code not work?
can you explain?
The inputs should be captured before the for loop is executed. In this case, a new input is expected for every iteration of the for loop. Try capturing the inputs first inside some variables and use those variables here. That will work.
You don't even need to have the cuboid list to be honest :)
print ([[a,b,c] for a in range(0,x+1) for b in range(0,y+1) for c in range(0,z+1) if a + b + c != n ])
ha!, I realized that a day later. Thanks for clearing it up though gkeswani92
bro can you please explain the code?