Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Give the following code, list1 = [x for x in range(10) if x % 3] list2 = [x for x in range(4)] list1.append(list2) What is

Give the following code,

list1 = [x for x in range(10) if x % 3] list2 = [x for x in range(4)] list1.append(list2) 

What is the value of len(list1)?

A.

5

B.

7

C.

8

D.

10

1 points

QUESTION 2

Suppose list1 = [2, 3, 5, 7]. Which of the following statement creates a copy of list1?

(Please choose all correct answers)

A.

list2 = list1

B.

list2 = list1[:]

C.

list2 = list1.copy()

D.

list2 = list(list1)

1 points

QUESTION 3

What will be displayed by the following code?

list1 = list("abcdef") for i in range(1, 6): list1[i-1] = list1[-i] for x in list1: print(x, end = " ") 
A.

a b c d e f

B.

f e d c b a

C.

a b c c b a

D.

f e d d e f

1 points

QUESTION 4

Which of the following code will print out

(2, 4, 6, 8)

A.
t = (1, 3, 5, 7) for i in range(len(t)): t[i] = t[i] + 1 print(t)
 
B.
t = (1, 3, 5, 7) t = (x+1 for x in t) print(t)
 
C.

t = (1, 3, 5, 7)

t = tuple([x+1 for x in t])

print(t)

D.

All of the above

1 points

QUESTION 5

Suppose s = {1, 2}, what is s * 2?

A.

{1, 2, 1, 2}

B.

{1, 2}

C.

[1, 2, 1, 2]

D.

Illegal operation

1 points

QUESTION 6

Given the following code, which of the expression evaluates to True?

l1 = list('california') l2 = list('corona') s1 = set(l1) s2 = set(l2) 

(Please choose all correct answers)

A.

l1 < l2

B.

l1 > l2

C.

s1 < s2

D.

s1 > s2

1 points

QUESTION 7

Given a dictionary, such as pb = {'Bob':1021, 'Charlie':1022, 'Dave':1300}, which of the following code will print out both key and value for each element in the dictionary?

A.
for i in range(len(pb)): print(pb[i], end = ';')
B.
for e in pb: print(e, end = ';')
C.
for e in pb.items(): print(e, end = ';')
D.
for e in pb.values(): print(e, end = ';')

1 points

QUESTION 8

Which of the following objects have to be of an immutable type?

(Please choose all correct answers)

A.

Elements in a list

B.

Elements in a tuple

C.

Elements in a set

D.

Keys in a dictionary

E.

Values in a dictionary

1 points

QUESTION 9

What will be displayed by the following code?

def disp(x = 1, y = 'a'): print(x, y) disp(y = 2, x = 'b') 
A.

b 2

B.

1 a

C.

2 b

D.

TypeError

1 points

QUESTION 10

What will be displayed by the following code?

def update(priceList, discount, isMember): if isMember: discount += 10 for i in range(len(priceList)): priceList[i] *= 1 - (discount / 100) priceList = [100.0, 400.0, 1000.0] discount = 10 update(priceList, discount, True) print(discount, priceList)

A.

10 [100.0, 400.0, 1000.0]

B.
20 [100.0, 400.0, 1000.0]
C.

10 [80.0, 320.0, 800.0]

D.

20 [80.0, 320.0, 800.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

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Question Can a self-employed person adopt a profit sharing plan?

Answered: 1 week ago