- 3

List=[1,1,2,3,5,8,13] print (list[list[4]])

Output 8 why??? Now position 4 is 5 but it display the 8

28th Apr 2019, 3:18 PM
Yogesh
Yogesh - avatar
9 ответов
+ 5
Yogeshwari M . If you want to print the 4 position The correct sintax to use is print(list[4]) When you do print(list(list[4]) You are printing list in position In the result of list[4]. That is position 5
28th Apr 2019, 3:45 PM
Anya
Anya - avatar
+ 4
n = list[4] What's the value of n? What's the value of list[n]?
28th Apr 2019, 3:29 PM
Anna
Anna - avatar
+ 4
print(list[4]) Output = 5 print(list[list[4]]) list[4] is equal to 5 So list[list[4]] is equal to list[5] So we have print(list[5]) Output is 8
28th Apr 2019, 3:30 PM
Anya
Anya - avatar
+ 2
Just look at your code carefully Here's what it says print(list[list[4]]) >> list[5] // 5 cames here the way that you told above >> 8 Simply it asks for the value corresponding to the value at index 4
28th Apr 2019, 3:30 PM
Seniru
Seniru - avatar
+ 2
Did you read everyone's explanations?
28th Apr 2019, 3:45 PM
Anna
Anna - avatar
+ 1
I can do ya print(list[list[4]]) It cames 8 not 5
28th Apr 2019, 3:39 PM
Yogesh
Yogesh - avatar
+ 1
Thankyou for ur explanation
28th Apr 2019, 3:49 PM
Yogesh
Yogesh - avatar
0
This question from the quiz has been bugging me for some time, trying to understand why the output is 8. Thanks to Anya's explanation I get what the code has been telling me all along. Talk about starring blind. Thank you, Anya.
14th Jul 2020, 8:47 AM
Van
Van - avatar
0
yh anya's explanation really helped clear the smoke in my mind..
23rd Sep 2020, 10:07 AM
KAS