+ 2

I have a question in python

what would be the answer to this code list = [1,1,2,3,5,8,13] print(list[list[4]]) and why is that the answer, thenks

24th Jul 2018, 2:45 PM
Alex
Alex - avatar
5 odpowiedzi
+ 2
The answer would be 8. That is because the computer first evaluates list[4] which is 5 (because indexing starts at 0). Then it would evaluate list[5] which is 8. list[list[4]] = list[5] = 8 You could run it at Code Playground to test it, though. Good luck with implementing the Fibonacci sequence!
24th Jul 2018, 3:01 PM
giannismach
giannismach - avatar
+ 12
list = [1,1,2,3,5,8,13] index value start from 0 in list so list[4]=5 so list[list[4]]=list[5]=8 so output will be 8
24th Jul 2018, 2:58 PM
GAWEN STEASY
GAWEN STEASY - avatar
+ 1
list=[1,1,2,3,5,8,13] print(list[list[4]]) it's output is 8 because let's take inner index i.e list[4] it's output is 5 now take outer one I.e list[5] whose output is 8
25th Jul 2018, 2:55 AM
Dare$devil
Dare$devil - avatar
- 2
8
24th Jul 2018, 5:05 PM
David
- 4
face command in Turkish if
24th Jul 2018, 4:38 PM
Abdullah