+ 1
what is the output of the program mentioned in the question.
What is the output of this code? list = [1, 1, 2, 3, 5, 8, 13] print(list[list[4]]) **THE ANSWERS IS 8 & HOW?
6 Answers
+ 3
list=[1,1,2,3,5,8,13]
print(list[list[4]])
Here you are indirectly referring to 8, this is how,
list[list[4]] => list[5] => 8.
+ 1
Because list[4] = 5
And list[5] = 8
+ 1
In list the index start from 0
So when u traverse from u get 5
------------------------------------------------------------
List[0 1 2 3 4 5 6 ]. (index reference)
List[1 1 2 3 5 8 13].(our question)
-------------------------------------------------------------
Now check inner one first
List[4] = 5
U can see the reference of index.
Now outer list
List[5] = 8
-------------------------------------------------------------
+ 1
thankyou so much priyal
0
list=[1,1,2,3,5,8,13]
list(list[list[4]])
You should start look at the inner or list[4]
Get the value of list[4]
Since the index is starting 0
Just count from 0 to 4
Then list[4] = 5
Since list[4]=5
Its look like this
list[list[4]] -> list[5]
Then list[5] = 8
Because the 5th index position is 8.
0
list[4] means the fifth element in list which equal to 5
list[5] means the sixth element in list which equal to 8