Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Chapter 06: How to work with lists and tuples Murach's Python Programming No Answers MULTIPLE CHOICE 1. To refer to an item in a list,

Chapter 06: How to work with lists and tuples

Murach's Python Programming

No Answers

MULTIPLE CHOICE

1. To refer to an item in a list, you code the list name followed by

a.

an index number in brackets, starting with the number 1

b.

an index number in parentheses, starting with the number 1

c.

an index number in brackets, starting with the number 0

d.

an index number in parentheses starting with the number 0

2. The __________ method adds an item to the end of a list.

a.

pop()

b.

append()

c.

insert()

d.

index()

3. To insert the item melon after grapes in the following list, you would use which of these methods?

fruit = ["apple", "banana", "grapes", "mangos", "oranges"]

a.

fruit.pop("melon", 3)

c.

fruit.insert(3, "melon")

b.

fruit.insert("melon", 3)

d.

fruit.append(3, "melon")

4. To remove the item mangos from the following list, you would use which of these methods?

fruit = ["apple", "banana", "grapes", "mangos", "oranges"]

a.

fruit.remove("mangos") or fruit.pop(3)

b.

fruit.remove(3) or fruit.pop("mangos")

c.

fruit = remove("mangos") or fruit = pop(3)

d.

fruit = pop("mangos")

5. When a function changes the data in a list, the changed list

a.

does not need to be returned because lists are mutable.

b.

is only available within that function.

c.

needs to be returned because lists are immutable.

d.

does not need to be returned because lists are immutable.

6. Which of the following is not true about a list of lists?

a.

You can use nested for statements to loop through the items in a list of lists.

b.

You can refer to an item in an inner list by using two indexes.

c.

To delete an item in the outer list, you first have to delete the list in the item.

d.

The inner lists and the outer list are mutable.

7. Which of the following functions randomly selects one item in a list?

a.

choice()

c.

lrandom()

b.

shuffle()

d.

randomitem()

8. Which of the following statements about list copies is not true? When you make a

a.

deep copy of a list, both variables refer to their own copy of the list.

b.

deep copy of a list, both variables refer to the same list.

c.

shallow copy of a list, both variables refer to the same list.

d.

shallow copy of a list, the list is immutable.

9. The primary difference between a tuple and a list is that a tuple

a.

has a limited range

b.

is indexed starting from 1

c.

is mutable

d.

is immutable

10. When you use a multiple assignment statement to unpack a tuple,

a.

you assign the tuple to a list

b.

you assign the tuple to a two or more variable names separated by commas

c.

you use a for statement to assign the values in the tuple to a list

d.

you use indexing to assign the values in the tuple to multiple variables

11. Given the following list, what is the value of ages[5]?

ages = [22, 35, 24, 17, 28]

a.

22

c.

28

b.

17

d.

None: Index error

12. Which of the following would create a list named numbers consisting of 3 floating-point items?

a.

numbers[1] = 5.3

numbers[2] = 4.8

numbers[3] = 6.7

c.

numbers = [0] * 3

b.

numbers = [5.3, 4.8, 6.7]

d.

numbers[3] = (5.3, 4.8, 6.7)

13. Given the following code, what is the value of my_name and what does the list consist of after the second statement is executed?

names = ["Lizzy", "Mike", "Joel", "Anne", "Donny"]

my_name = name.pop()

a.

my_name = "Donny", names = ["Lizzy", "Mike", "Joel", "Anne", "Donny"]

b.

my_name = "Lizzy", names = ["Mike", "Joel", "Anne", "Donny"]

c.

my_name = "Donny", names = ["Lizzy", "Mike", "Joel", "Anne"]

d.

Error: must specify item number with the pop() method

14. Given the following code, what would the list consist of after the second statement?

ages = [22, 35, 24, 17, 28]

ages.insert(3, 4)

a.

ages = [22, 35, 24, 4, 17, 28]

c.

ages = [22, 35, 24, 17, 3, 28]

b.

ages = [22, 35, 3, 24, 17, 28]

d.

ages = [22, 35, 24, 17, 4, 28]

15. What is the value of the total variable after the following code executes?

prices = [10, 15, 12, 8]

total = 0

i = 1

while i < len(prices):

total += prices[i]

i += 1

print(total)

a.

0

b.

35

c.

8

d.

45

16. What will display after the following code executes?

def add_item(list, food):

food = "apple pie"

list.append(food)

def main():

lunch = ["sandwich", "chips", "pickle"]

food = "banana"

add_item(lunch, food)

print(lunch)

main()

a.

['sandwich', 'chips', 'pickle', 'banana']

b.

['sandwich', 'chips', 'pickle', 'banana', 'apple pie']

c.

['sandwich', 'chips', 'pickle', 'apple pie']

d.

Error: list is undefined

Code Example 6-1

def main():

students = [["Lizzy", 73, "C"],

["Mike", 98, "A"],

["Joel", 88, "B+"],

["Anne", 93, "A"]]

for student in students:

for item in student:

print(item, end=" ")

if __name__ == "__main__":

main()

17. Refer to Code Example 6-1: What is the value of students[2][1]?

a.

Joel

b.

88

c.

Joel, 88, B+

d.

B+

18. Refer to Code Example 6-1: What is in the second row of the students list?

a.

"Mike", 98, "A"

c.

73, 98, 88, 93

b.

"Joel", 88, "B+"

d.

"C", "A", "B+", "A"

19. Which of the following creates a tuple of six strings?

a.

vehicles = ("sedan","SUV","motorcycle","bicycle","hatchback","truck")

b.

vehicles = ["sedan","SUV","motorcycle","bicycle","hatchback","truck"]

c.

vehicles = (sedan, SUV, motorcycle, bicycle, hatchback, truck)

d.

vehicles = "sedan","SUV","motorcycle","bicycle","hatchback","truck"

20. Given the tuple that follows, which of the following assigns the values in the tuple to variables?

numbers = (22, 33, 44, 55)

a.

for item in numbers:

item[i] = numbers[i]

c.

w = numbers

x = numbers

y = numbers

z = numbers

b.

w, x, y, z = numbers.unpack()

d.

w, x, y, z = numbers

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Describe the nature of leadership succession.

Answered: 1 week ago