+ 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]])
5 Respostas
+ 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 .
+ 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])
+ 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
+ 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
0
Still doesn't understant why it sums 1 to the index.