+ 1

Module 2 Quiz 1

"""Can anyone exlpain why the output of this code is 8 and not 5? Thank you very much.""" list = [1, 1, 2, 3, 5, 8, 13] print(list[list[4]])

14th Jun 2018, 4:37 PM
ailobe
5 odpowiedzi
+ 3
it is list[list[4]]. now list[4] = 5. so, instead of list[list[4]] we can put list[5] which is 8. so answer is 8 not 5 .
14th Jun 2018, 4:46 PM
Raj Chhatrala
Raj Chhatrala - avatar
+ 2
try to print like below for better understanding... """Can anyone exlpain why the output of this code is 8 and not 5? Thank you very much.""" list = [1, 1, 2, 3, 5, 8, 13] p = list[4] print (p) print(list[p])
14th Jun 2018, 5:02 PM
$¢𝐎₹𝔭!𝐨𝓝
$¢𝐎₹𝔭!𝐨𝓝 - avatar
+ 2
Thanks everybody for your responses! I finally understood it, thanks to the comments in the quiz itself (I didn't know that feature). It just couldn't click to me that we chose the index number from the list itself by calling that number's index... now it's clear: print(list[list[4]]) -> print(list[5]) But before I kept thinking it was a list of list crazy thing. I started learning to program less than a week ago. I like sololearn cause it's like duolingo. Also like this video on python: https://youtu.be/N4mEzFDjqtA
14th Jun 2018, 6:00 PM
ailobe
+ 1
The list indexing starts from 0 not 1. list=[1, 1, 2, 3, 5, 8, 13] list[0]==1 list[1]==1 list[2]==2 list[3]==3 list[4]==5 list[5]==8 #Maybe that is your problem
14th Jun 2018, 5:28 PM
李立威
0
Still doesn't understant why it sums 1 to the index.
14th Jun 2018, 5:10 PM
ailobe