Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IGNORE THE EMPTY BOXES... Consider this code. What is the value of the list x after execution. def foo(y): for n in range(len(y)): y[n] =

IGNORE THE EMPTY BOXES...

Consider this code. What is the value of the list x after execution.

def foo(y): for n in range(len(y)): y[n] = y[n] + 1

x=[1, 3, 5] foo(x)

[1, 3, 5]

[2., 4, 6]

[0, 0, 0]

[1, 1, 1]

How do you copy the contents of list p?

p = [10, 15.5, 13.2, 20.1]

values[10] = p

values = list(p)

values[10] = p[10]

all of the above

What is the result of this code?

values = [1991, 1875, 1980, 1965, 2000] values.sort()

[1991, 1875, 1980, 1965, 2000]

[2000, 1991, 1980, 1965, 1875]

[2000, 1991, 1875, 1980, 1965]

[1875, 1965, 1980, 1991, 2000]

Which creates an alias for p?

p = [10.00, 15.50, 13.25, 20.15]

values[10] = p

values = p

values[10] = p[10]

None of the above

What are the contents of the list after this executes?

states = ["Alaska", "Hawaii", "Florida", "Maine", "Ohio", "Florida"] states.remove("Florida")

["Alaska", "Hawaii", "Maine", "Ohio", "Florida"]

["Hawaii", "Hawaii", "Maine", "Ohio"]

["Alaska", "Hawaii", "Florida", "Maine", "Ohio"]

["Alaska", "Hawaii", "Florida", "Maine", "Ohio", "Florida"]

What is displayed when it runs?

values = [4, 12, 0, 1, 5] print(values[1])

0

1

4

12

.

What are the keys in f?

f = {"Apple": "Green", "Banana": "Yellow"}

Apple and Banana

Green and Yellow

Apple, Green, Banana and Yellow

The dictionary does not have any keys

Which of the following statements checks to see if the key 'Apple' is already in the dictionary named fruit? .

if "Apple" in fruit:

if "Apple" = (fruit):

if fruit in "Apple":

if fruit.contains("Apple"):

What is output by the following code segment?

values = ["Q", "W", "E", "R", "T", "Y"] print(values[2 : 4])

["W", "E"]

["W", "E", "R"]

["E", "R"]

["E", "R", "T"]

"For this, what value is at index 5? values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]"

5

6

7

4

"What happens here? sum([1, 2, 3, 4, 5])"

121

16

15

14

What is output by the following code segment?

values = ["Q", "W", "E", "R", "T", "Y"] print(values[ -1 : ])

["Y"]

["T", "Y"]

["Q", "u", "E", "R"]

["E", "R", "T", "Y"]

____ returns the number of elements in list L.

len(L)

siz(L)

length(L)

size(L)

Which list method removes and returns the element at the end of the list.

pop

remove

get

append

"In Python, a ____ associates a set of keys with data values."

string

tuple

list

dictionary

"What is printed after executing the following code?

somelist = ["a", "b", "c", "x", "y", "z"] for i in range(0, len(somelist), 2) print(somelist[i], end = " ")

abcxyz

a b c x y z

acy

bcxz

Which statement gets the length of the list values?

numValues = length(values)

numValues = len(values)

numValues = size(values)

numValues = values.length

What is the difference between a list and a dictionary?

a list is a superset of a dictionary

a dictionary can access elements by position

a list stores individual elements but a dictionary stores key/value pairs

returns -1

raises an exception

returns an empty set

returns None

What is output by the following code segment?

values = ["Q", "W", "E", "R", "T", "Y"] print(values[ 3 : ])

["W", "E"]

["R", "T", "Y"]

["Q", "u", "E", "R"]

["E", "R", "T", "Y"]

What is displayed when this runs?

values = [1, 2, 3, 4, 5] moreValues = values moreValues[3] = 6 print(values)

[1, 2, 3, 4, 5]

[1, 2, 6, 4, 5]

[1, 2, 3, 6, 5]

[1, 2, 3, 4, 5, 6]

What is displayed when it is executed?

x = {} x["Hello"] = [4, 5] x["Hello"].append("World") print(x["Hello"])

Hello

HelloWorld

[4, 5]

[4, 5, "World"]

"Given the following what are the contents of the list fullNames?

firstNames = ["Joe", "Jim", "Betsy", "Shelly"] lastNames = ["Jones", "Patel", "Hicks", "Fisher"] fullNames = firstNames + LastNames

["Joe", "Jones", "Jim", "Patel", "Betsy", "Hicks", "Shelly", "Fisher"]

["Joe Jones", "Jim Patel", "Betsy Hicks", "Shelly Fisher"]

["Joe", "Jim", "Betsy", "Shelly", "Jones", "Patel", "Hicks", "Fisher"]

["Joe", "Jim", "Betsy", "Shelly"]

"The items in a dictionary are stored in sequential order that can be accessed by index, like with a list."

True

False

"When you use a collection of unique items, _____"

lists are more efficient than sets

sets are more efficient that lists

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

Recommended Textbook for

Learning PostgreSQL

Authors: Salahaldin Juba, Achim Vannahme, Andrey Volkov

1st Edition

178398919X, 9781783989195

More Books

Students also viewed these Databases questions

Question

What are some sources of ethical guidance?

Answered: 1 week ago