You are viewing a single comment's thread. Return to all comments →
in py2 can be w/o int()
x,y,z,n = [input() for i in range(4)]
print [[a,b,c] for a in range(x+1) for b in range(y+1) for c in range(z+1) if a+b+c != n]
WHAT IS THE 4 INDICATES HERE
range(4) indicates 0,1,2,3 i.e the numbers we have given are allocated to the x,y,z,n respectively
4 input() s
what is the reason for x+1 y+1 and many more
In simple words it signifies that the range is inclusive of max limit
like the control statement
range() is inclusive of the first number (which is 0, by default), but exclusive of the last one. So "for i in range(5): print i" will give you 0,1,2,3,4 (but not five). In this case, we want to also include the number given, hence the +1. The 0 for the first part range(0,5), is optional, since we are starting at the beginning.
in python iteration occurs one less than the give variable
Can you help me with this logic ? why we check for a+ b +c !=n
read the question carefully you can understand easily.in the question they have given values inside the nested list must not equal to n so we have given a+b+c!=n
why does this code run only for python 2 and not python 3?