0

Python 3 Control Structures Quiz Question #1

I have been looking at this code, and though the answer is that it prints 8, I cannot figure out how it gets there. list = [1, 1, 2, 3, 5, 8, 13] print(list[list[4]]) print(list[4]) /* This returns the 4th indexed number in the list, which is 5 (starting at 0 and counting through the numbers.) */ print(list) //This produces the original 1, 1, 2, 3, 5, 8, 13. // How does nesting the list variable in the print function return 8?

30th May 2018, 3:20 AM
ubuntu+mate
ubuntu+mate - avatar
1 Answer
+ 1
Aha. Gotcha. Thank you much, Ace! [list4] returns 5, which becomes the index to then return 8. Cool!
31st May 2018, 1:38 AM
ubuntu+mate
ubuntu+mate - avatar