ch 6

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Given the following code, what would the list consist of after the second statement? ages = [22, 35, 24, 17, 28] ages.insert(3, 4) Select one: a. ages = [22, 35, 24, 4, 17, 28] b. ages = [22, 35, 24, 17, 3, 28] c. ages = [22, 35, 24, 17, 4, 28] d. ages = [22, 35, 3, 24, 17, 28]

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

To refer to an item in a list, you code the list name followed by Select one: a. an index number in brackets, starting with the number 1 b. an index number in brackets, starting with the number 0 c. an index number in parentheses starting with the number 0 d. an index number in parentheses, starting with the number 1

an index number in brackets, starting with the number 0

The __________ method adds an item to the end of a list. Select one: a. append() b. pop() c. index() d. insert()

append()

Which of the following functions randomly selects one item in a list? Select one: a. lrandom() b. randomitem() c. shuffle() d. choice()

choice()

Which of the following statements about list copies is not true? When you make a Select one: a. shallow copy of a list, the list is immutable. b. shallow copy of a list, both variables refer to the same list. c. deep copy of a list, both variables refer to the same list. d. deep copy of a list, both variables refer to their own copy of the list.

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

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) Select one: a. 8 b. 35 c. 45 d. 0 witch ogre

35

Given the following list, what is the value of names[2]? names = ["Lizzy", "Mike", "Joel", "Anne", "Donald Duck"] Select one: a. Joel b. None, improper assignment of "Donald Duck" due to space in the name c. Mike d. Anne

Joel

Given the following list, what is the value of ages[5]? ages = [22, 35, 24, 17, 28] Select one: a. None: Index error b. 28 c. 17 d. 22

None: Index error

Given the following code, what would be displayed after the code executes? def main(): furry_pets = ["dog", "cat", "ferret", "hamster", "bunny"] feathered_pets = ["canary", "parrot", "budgie", "hawk"] all_pets = furry_pets + feathered_pets new_pets =[] i = 0 for item in all_pets: if item[i][0] == "c": new_pets.append(item) print("The pet store sells:", all_pets) print("These start with the letter c:", new_pets) Select one: a. The pet store sells: ['bunny', 'cat', 'dog', 'ferret', 'hamster', 'budgie', 'canary', 'hawk', 'parrot'] These start with the letter c: ['cat', 'canary'] b. The pet store sells: ["dog", "cat", "ferret", "hamster", "bunny"] These start with the letter c: ['cat'] c. The pet store sells: ['dog', 'cat', 'ferret', 'hamster', 'bunny', 'canary', 'parrot', 'budgie', 'hawk'] These start with the letter c: ['cat', 'canary'] d. The pet store sells: ['canary', 'parrot', 'budgie', 'hawk'] These start with the letter c: ['canary']

The pet store sells: ['dog', 'cat', 'ferret', 'hamster', 'bunny', 'canary', 'parrot', 'budgie', 'hawk'] These start with the letter c: ['cat', 'canary']

Which of the following is not true about a list of lists? Select one: a. To delete an item in the outer list, you first have to delete the list in the item. b. You can use nested for statements to loop through the items in a list of lists. c. The inner lists and the outer list are mutable. d. You can refer to an item in an inner list by using two indexes.

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

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() Select one: a. ['sandwich', 'chips', 'pickle', 'banana', 'apple pie'] b. Error: list is undefined c. ['sandwich', 'chips', 'pickle', 'apple pie'] d. ['sandwich', 'chips', 'pickle', 'banana']

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

When a function changes the data in a list, the changed list Select one: a. needs to be returned because lists are immutable. b. does not need to be returned because lists are immutable. c. is only available within that function. d. does not need to be returned because lists are mutable.

does not need to be returned because lists are mutable.

To insert the item "melon" after "grapes" in the following list, you would use which of these methods? fruit = ["apple", "banana", "grapes", "mangos", "oranges"] Select one: a. fruit.append(3, "melon") b. fruit.insert(3, "melon") c. fruit.pop("melon", 3) d. fruit.insert("melon", 3)

fruit.insert(3, "melon")

To remove the item "mangos" from the following list, you would use which of these methods? fruit = ["apple", "banana", "grapes", "mangos", "oranges"] Select one: a. fruit = pop("mangos") b. fruit = remove("mangos") or fruit = pop(3) c. fruit.remove("mangos") or fruit.pop(3) d. fruit.remove(3) or fruit.pop("mangos")

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

What would be displayed after the following code snippet executes? costumes = ["ghost", "witch", "elf", "ogre"] name = "elf" if name in costumes: costumes.remove(name) for item in costumes: print(item) Select one: a. ghost witch ogre b. "ghost", "witch", "elf", "ogre" c. ghost, witch, ogre d. "ghost" "witch" "elf" "ogre"

ghost witch ogre

The primary difference between a tuple and a list is that a tuple Select one: a. has a limited range b. is immutable c. is indexed starting from 1 d. is mutable

is immutable

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() Select one: a. my_name = "Donny", names = ["Lizzy", "Mike", "Joel", "Anne"] b. Error: must specify item number with the pop() method c. my_name = "Lizzy", names = ["Mike", "Joel", "Anne", "Donny"] d. my_name = "Donny", names = ["Lizzy", "Mike", "Joel", "Anne", "Donny"]

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

Which of the following would create a list named numbers consisting of 3 floating-point items? Select one: a. numbers[3] = (5.3, 4.8, 6.7) b. numbers[1] = 5.3 numbers[2] = 4.8 numbers[3] = 6.7 c. numbers = [5.3, 4.8, 6.7] d. numbers = [0] * 3

numbers = [5.3, 4.8, 6.7]

Given the tuple that follows, which of the following assigns the values in the tuple to variables? numbers = (22, 33, 44, 55) Select one: a. w = numbers x = numbers y = numbers z = numbers b. w, x, y, z = numbers c. for item in numbers: item[i] = numbers[i] d. w, x, y, z = numbers.unpack()

w, x, y, z = numbers

When you use a multiple assignment statement to unpack a tuple, Select one: 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

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


Set pelajaran terkait

Bio 240: Plant Evolution and Life Cycles

View Set

Vocabulary Workshop Level E, Unit 11

View Set

Structuralism Key Terms and Concepts

View Set

LSAT Logical Reasoning Question Types

View Set

HESI Patient Review--Pediatrics-Out-patient Peds (Adolescents)

View Set

Chapter 7: Anatomy and Physiology of Pregnancy (includes chp 12 Q) NCLEX 59Qw/exp ***Definitely LOOK OVER ***

View Set

Biology 1107: Chapter 7 & 8 Homework

View Set