Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PYTHON MULTI CHOICE QUESTIONS 1a) What is the value of names after the following code segment has run? names = [] names.append(Amy) names.append(Bob) names.append(Peg) names[0]

PYTHON MULTI CHOICE QUESTIONS

1a) What is the value of names after the following code segment has run?

names = [] names.append("Amy") names.append("Bob") names.append("Peg") names[0] = "Cy" names.insert(0, "Ravi") 
['Ravi', 'Cy', 'Amy', 'Bob', 'Peg'] 
['Cy', 'Amy', 'Bob', 'Peg'] 
['Ravi', 'Cy', 'Bob', 'Peg'] 
['Ravi', 'Amy', 'Bob', 'Peg'] 

1b) What is the value of the variable indexValue after the following code snippet runs?

states = ["Alaska", "Hawaii", "Florida", "Maine", "Ohio", "Florida"] indexValue = states.index("Pennsylvania") 

1c) Which statement(s) allows us to initialize the list numbers with 10 elements all set to zero?

numbers = [0] 
numbers[10] = 0 
numbers = [0] * 10 
numbers[10] = [0] * 10 

1d) What is the resulting content of the list letters after this code snippet?

letters = list("abcdefg") 

letters contains a list with the contents: ["a", "b", "c", "d", "e", "f", "g"]

letters contains a list with the contents: ["abcdefg"]

Invalid Type Error

letters contains a list with the contents: ("abcdefg")

1e) Which of the following code segments will result in values containing the list ["Hydrogen", "Helium", "Lithium"]?

values = [] values.append("Lithium") values.append("Helium") values.append("Hydrogen") 
values = [] values.append("Hydrogen") values.append("Helium") values.append("Lithium") 
values = ["Hydrogen"] values.append("Helium", "Lithium") 
values = [] values.append(["Hydrogen", "Helium", "Lithium"]) 

1f) Lists are mutable. The elements of a list might be immutable types (like int, string, float).

-True

-False

1g) A list is a heterogeneous compound type, allowing elements of mixed types to be part of the same list object.

-True

-False

1h) Assume the following statement appears in a program:

mylist = [] 

Which of the following statements would you use to add the string 'Labrador' to the list at index 0?

-mylist[0] = 'Labrador' 
-mylist.insert(0, 'Labrador') 
-mylist.append('Labrador') 
-mylist.insert('Labrador', 0) 

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

Why is there a need for aggregate planning?

Answered: 1 week ago

Question

Relational Algebra

Answered: 1 week ago

Question

3. Identify the methods used within each of the three approaches.

Answered: 1 week ago