Introduction To Programming - Chapter 7

25 July 2022
4.7 (114 reviews)
25 test answers

Unlock all answers in this set

Unlock answers (21)
question
b. elements
answer
What are the data items in the list called? a. data b. elements c. items d. values
question
d. [0, 2, 4, 6, 8]
answer
Which list will be referenced by the variable number after the execution of the following code? number = range(0, 9, 2) a. [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] b. [1, 3, 5, 7, 9] c. [2, 4, 6, 8] d. [0, 2, 4, 6, 8]
question
a. del statement
answer
What would you use if an element is to be removed from a specific index? a. del statement b. remove method c. index method d. slice method
question
b. -1
answer
What is the first negative index in a list? a. 0 b. -1 c. -0 d. Size of the string or list minus one
question
c. insert
answer
What method can be used to place an item in the list at a specific index? a. append b. index c. insert d. Add
question
c. [1, 2, 1, 2, 1, 2]
answer
What would be the value of the variable list after the execution of the following code? list = [1, 2] list = list * 3 a. [1, 2] * 3 b. [3, 6] c. [1, 2, 1, 2, 1, 2] d. [[1, 2], [1, 2], [1, 2]]
question
a. [1, 2, 3, 10]
answer
What would be the value of the variable list after the execution of the following code? list = [1, 2, 3, 4] list[3] = 10 a. [1, 2, 3, 10] b. [1, 2, 10, 4] c. [1, 10, 10, 10] d. invalid code
question
b. +
answer
What method or operator can be used to concatenate lists? a. * b. + c. % d. concat
question
b. [4, 5, 6]
answer
What would be the value of the variable list2 after the execution of the following code? list1 = [1, 2, 3] list2 = list1 list1 = [4, 5, 6] a. [1, 2, 3] b. [4, 5, 6] c. [1, 2, 3, 4, 5, 6] d. invalid code
question
a. [1, 2, 3]
answer
What would be the value of the variable list2 after the execution of the following code? list1 = [1, 2, 3] list2 = [] for element in list1 list2.append(element) list1 = [4, 5, 6] a. [1, 2, 3] b. [4, 5, 6] c. [1, 2, 3, 4, 5, 6] d. invalid code
question
c. nested list
answer
When working with multiple sets of data, one would typically use a(n) _____. a. list b. tuple c. nested list d. Sequence
question
d. once a tuple is created, it cannot be changed
answer
The primary difference between a tuple and list is that _____. a. when creating a tuple you don't use commas to separate elements b. a tuple can only include string elements c. a tuple cannot include lists as elements d. once a tuple is created, it cannot be changed
question
c. Processing a tuple is faster than processing a list.
answer
What is the advantage of using tuples over lists? a. Tuples are not limited in size. b. Tuples can include any data type as an element. c. Processing a tuple is faster than processing a list. d. There is no advantage.
question
b. tuple
answer
What method can be used to convert a list to a tuple? a. append b. tuple c. insert d. list
question
d. list
answer
What method can be used to convert a tuple to a list? a. append b. tuple c. insert d. list
question
True
answer
True/False: Invalid indexes do not cause slicing expressions to raise an exception
question
True
answer
True/False: Lists are dynamic data structures such that items may be added to them or removed from them.
question
False
answer
True/False: Arrays, which most other programming languages allow, have much more capabilities than list structures.
question
False
answer
True/False: A list cannot be passed as an argument to a function
question
False
answer
True/False: The remove method removes all occurrences of the item from a list
question
False
answer
True/False: The sort method rearranges the elements of a list so they appear in ascending or descending order.
question
True
answer
True/False: The first step in calculating the average of the values in a list is to get the total of the values.
question
False
answer
True/False: Indexing starts at 1, so the index of the first element is 1, the index of the second element is 2, and so forth.
question
True
answer
True/False: The index - 1 identifies the last element in a list
question
True
answer
True/False: In slicing, if the end index specifies a position beyond the end of the list, Python will use the length of the list instead.