Ch 10 & 11

¡Supera tus tareas y exámenes ahora con Quizwiz!

What is list("abcd")? - ['a', 'b', 'c', 'd'] - ['ab'] - ['abcd'] - ['cd']

- ['a', 'b', 'c', 'd']

If a key is not in the list, the binarySearch function returns _________.

-(insertion point + 1)

What will be displayed by the following code? myList = [1, 2, 3, 4, 5, 6] for i in range(1, 6): myList[i - 1] = myList[i] for i in range(0, 6): print(myList[i], end = " ")

2 3 4 5 6 6

Suppose list1 = [1, 2, 3]. What is the output of the following code? for i in list1: print(i * 2, end = ',')

2,4,6,

Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3]. What is len(list1)?

8

Suppose list1 is [1, 3, 2, 4, 5, 2, 1, 0]. What is list1[-1]?

0

What will be displayed by the following code if you enter 1 5 5 5 5 5 1 in one line? myList = input("Enter numbers in a line: ").split() max = myList[0] indexOfMax = 0 for i in range(1, len(myList)): if myList[i] > max: max = myList[i] indexOfMax = i print(indexOfMax)

1

What will be displayed by the following code? m = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] print(m[0][0])

1

How many elements are in m = [[x, y] for x in range(0, 4) for y in range(0, 4)]?

16

Use the selectionSort function presented in this section to answer this question. Assume lst is [3.1, 3.1, 2.5, 6.4, 2.1], what is the content of list after the first iteration of the outer loop in the function?

2.1, 3.1, 2.5, 6.4, 3.1

Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3]. What is max(list1)?

25

What will be displayed by the following code? def f(value, values): v = 1 values[0] = 44 t = 3 v = [1, 2, 3] f(t, v) print(t, v[0])

3 44

Assume x = [[1, 2], [3, 4, 5], [5, 6, 5, 9]]. What are len(x), len(x[0]), len(x[1]), and len(x[2])?

3, 2, 3, and 4

What will be displayed by the following program? values = [[3, 4, 5, 1], [33, 6, 1, 2]] v = values[0][0] for row in range(0, len(values)): for column in range(0, len(values[row])): if v < values[row][column]: v = values[row][column] print(v)

33

What will be displayed by the following code? data = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]] def ttt(m): v = m[0][0] for row in m: for element in row: if v < element: v = element return v print(ttt(data[0]))

4

What will be displayed by the following code? data = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]] print(data[1][0][0])

5

Suppose list1 is [1, 3, 2]. What is sum(list1)?

6

list1 = [11, 2, 23] and list2 = [11, 2, 2], list1 < list2 is ________

False

list1 = [11, 2, 23] and list2 = [2, 11, 23], list1 == list2 is ________

False

What will be displayed by the following program? values = [[3, 4, 5, 1], [33, 6, 1, 2]] for row in values: row.sort() for element in row: print(element, end = " ") print()

The program prints 1 3 4 5 followed by 1 2 6 33 on a new line

"Welcome to Python".split() is ________

["Welcome", "to", "Python"]

What is list("a#b#c#d").split('#')?

['a', 'b', 'c', 'd']

Suppose list1 = [0.5 * x for x in range(0, 4)]. list1 is ________

[0.0, 0.5, 1.0, 1.5]

What will be displayed by the following code? def f(i, values = []): values.append(i) return values f(1) f(2) v = f(3) print(v)

[1, 2, 3]

Suppose list1 is [1, 3, 2]. What is list1 * 2?

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

Suppose list1 is [1, 3, 2, 4, 5, 2, 1, 0]. What is list1[: -1]?

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

What will be displayed by the following code? list1 = [1, 3] list2 = list1 list1[0] = 4 print(list2)

[4, 3]

What will be displayed by the following code? def f(values): values[0] = 44 v = [1, 2, 3] f(v) print(v)

[44, 2, 3]

For m = [[x, x + 1, x + 2] for x in range(0, 3)], m is _______.

[[0, 1, 2], [1, 2, 3], [2, 3, 4]]

What will be displayed by the following code? points = [[1, 2], [3, 1.5], [0.5, 0.5]] points.sort() print(points)

[[0.5, 0.5], [1, 2], [3, 1.5]]

If the binary search function returns -4, where should the key be inserted if you wish to insert the key into the list?

at index 3

__________ creates a list. Please select all that apply. list1 = list(range(1, 4)) list1 = [1, "3", "red"] list1 = [12, 4, 4] list1 = [] list1 = list("123")

list1 = list(range(1, 4)) list1 = [1, "3", "red"] list1 = [12, 4, 4] list1 = [] list1 = list("123")

Use the selectionSort function presented in this section to answer this question. What is list1 after executing the following statements? list1 = [3.1, 3.1, 2.5, 6.4] selectionSort(list1)

list1 is 2.5 3.1, 3.1, 6.4

To add 5 to the end of list1, use _______.

list1.append(5)

To insert 5 to the third position in list1, use _______. - list1.append(3, 5) - list1.insert(3, 5) - list1.insert(2, 5) - list1.add(3, 5)

list1.insert(2, 5)

To remove string "red" from list1, use _______.

list1.remove("red")

Suppose list1 is [1, 3, 2, 4, 5, 2, 1, 0]. __________ returns the first element in the list.

list1[0]

Which of the following statistics functions do you use to obtain the most common value in a list? - median - mode - middle - mean

mode

Suppose list1 is [1, 3, 2, 4, 5, 2, 1, 0]. Which of the following is correct? Please select all that apply. - print(list1[:-2]) - print(list1[0]) - print(list1[:2]) - print(list1[4:6])

print(list1[:-2]) print(list1[0]) print(list1[:2]) print(list1[4:6])


Conjuntos de estudio relacionados

Article 320-Armored Cable (Type AC)

View Set

Intro to Physics and Chemistry:Ch. 4

View Set

Exam 2 SLIDES // Leveraging IS in Business

View Set

A&P 1- Chapter 5 Mastering Assignments

View Set

AIS: Chapters 1-4 (Missing Questions Due to Images)

View Set

Chapter 35 Forms of Business Organizations

View Set

2.b) The Australian Constitution: the protection of rights

View Set