+ 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?

19th May 2020, 6:22 AM
Ummadisetty . Lakshmi Venkata Mallikarjuna
Ummadisetty . Lakshmi Venkata Mallikarjuna - avatar
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.
19th May 2020, 6:29 AM
Kiran Deep Naidu
Kiran Deep Naidu - avatar
+ 1
Because list[4] = 5 And list[5] = 8
19th May 2020, 6:30 AM
A͢J
A͢J - avatar
+ 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 -------------------------------------------------------------
19th May 2020, 6:43 AM
Priyal Vyas
Priyal Vyas - avatar
+ 1
thankyou so much priyal
19th May 2020, 6:49 AM
Ummadisetty . Lakshmi Venkata Mallikarjuna
Ummadisetty . Lakshmi Venkata Mallikarjuna - avatar
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.
19th May 2020, 6:50 AM
Jefferson Jadoc
Jefferson Jadoc - avatar
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
19th May 2020, 7:54 AM
Ahmed Muhammed
Ahmed Muhammed - avatar