Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. What will the following code display? values = [2, 4, 6, 8, 10] print(values[

ID: 3756319 • Letter: 1

Question

1. What will the following code display?

values = [2, 4, 6, 8, 10]

print(values[1:3])

[4,6]

[2,4,6]

[4,6,8]

[2,4]

2. Suppose that myList is [3, 4, 5, 20, 5, 25, 1, 3], what is myList.count(5) ?

0

4

1

2

3.

What is the output of the following code?

>>> a={1,2,3}

>>> b=frozenset([3,4,5])

>>> a-b

{1,2}

Error since the difference between a set and a frozen set cannot be determined

Error because of unsupported operand type for set data type

frozenset({1,2})

3.

Suppose that list1 is [1, 3, 2], What is the output of list1 * 2 ?

[2, 6, 4]

[1, 3, 2, 1, 3]

[1, 3, 2, 3, 2, 1]

[1, 3, 2, 1, 3, 2]

4. Which of the following built-in functions returns all of a dictionary's keys and their associated values as a sequence of tuples?

keys_values()

values()

items()

get()

a.

[4,6]

b.

[2,4,6]

c.

[4,6,8]

d.

[2,4]

Explanation / Answer

1) What will the following code display?

values = [2, 4, 6, 8, 10]

print(values[1:3])

The answer is a ([4,6])

2)  Suppose that myList is [3, 4, 5, 20, 5, 25, 1, 3], what is myList.count(5) ?

The answer is d (2)

3) What is the output of the following code?

>>> a={1,2,3}

>>> b=frozenset([3,4,5])

>>> a-b

The answer is a ({1,2})

4) Suppose that list1 is [1, 3, 2], What is the output of list1 * 2 ?

The answer is d ([1, 3, 2, 1, 3, 2])

5) Which of the following built-in functions returns all of a dictionary's keys and their associated values as a sequence of tuples?

The answer is c (items())