You are viewing a single comment's thread. Return to all comments →
Please explain for me why you use range(4)
did you got the output for the above one by using list comprehension?
This expression is used for reducing the repetitive statements in reading the inputs from console.
range(x,y) will create a range of elements from x to y-1
if only one parameter is passed x is assumed to be 0
so range(y) will create elements in range from 0 till y-1
so here range(4) will create a range which includes 0,1,2,3 hence the loop will iterate 4 times as there are 4 elements
can you write the complete code snippet using the range(4), I'm getting error. Thanks!
it will take 4 inputs i.e from 0 to 3...
because we have four variables x,y,z,n
because there is 4 inputs ! hope you understand
he want to take input of 4 numbers so in range it counts from 1 then x later until 4 means till n
to get 4 inputs. we are looping the input().
@annguyen bcz its starts from 0 end to 3
it's because since it has to take 4 inputs
for the first iteration it takes the 'x' input
and for second it takes 'y'
similarly for third it takes "z"
finally foe third it takes "n"