Lesson 6 Dealing with Sequences of Objects Chapter 1: Introduction Chapter 2: Lists [2.1] List [2.2] Accessing elements in a list [2.3] Quiz [2.4] List slicing [2.5] Nested List Chapter 3: More on lists Chapter 4: for loops Chapter 5: Applied problem solving Chapter 6: An army of robots Chapter 7: Tuples Chapter 8: Strings as a sequence Chapter 9: Testing and debugging Chapter 10: Sequences style guide Chapter 11: Summary Chapter 2: Lists Quiz face Josiah Wang Quick quiz! There are some teaching materials in here, so don’t skip it! 1 2 3 4 5 6 7 ❮ ❯ Question 1 What is the output of the following code snippet? Type Error if it results in an error. numbers = [11, 12, 13, 14, 15, 16] print(numbers[1]) Output 12 Explanation: Remember that list indices start at 0, so numbers[1] is the second element in the list. Check answer! Question 2 What is the output of the following code snippet? Type Error if it results in an error. numbers = [11, 12, 13, 14, 15, 16] print(numbers[3]) Output 14 Explanation: The index 3 refers to the 4th element in the list, so it's 14. Check answer! Question 3 What is the output of the following code snippet? Type Error if it results in an error. numbers = [11, 12, 13, 14, 15, 16] print(numbers[6]) Output Error Explanation: There are six items in the list, so the last index is 5. Python will give you an error if you try to go beyond 5. Try it out in an interactive prompt yourself to see what kind of error Python gives you! Check answer! Question 4 Write a function call to count the number of elements in a list called numbers? Hint: you have used this function quite a bit so far! numbers = [11, 12, 13, 14, 15, 16] Output len(numbers) Explanation: You can get the length/size of the list with the len() function. Check answer! Question 5 What is the output of the following code snippet? Type Error if it results in an error. numbers = [11, 12, 13, 14, 15, 16] print(numbers[-2]) Output 15 Explanation: This refers to the second item from the end of the list. Check answer! Question 6 What is the output of the following code snippet? Type Error if it results in an error. numbers = [11, 12, 13, 14, 15, 16] print(numbers[-7]) Output Error Explanation: Again, you will get an IndexError: list index out of range. Check answer! Question 7 What is the output of the following code snippet? Type Error if it results in an error. numbers = [11, 12, 13, 14, 15, 16] print(numbers[-6] == numbers[0]) Output True Explanation: Both numbers[0] and numbers[-6] have the same value. In fact, in this case they both point to the exact same object! Check answer!