python chapter 10

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

10.30 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]

Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after list1.extend([34, 5])?

[3, 4, 5, 20, 5, 25, 1, 3, 34, 5]

Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is max(list1)

25

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

false

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

0

Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is min(list1)?

1

What will be displayed by the following code? myList = [1, 5, 5, 5, 5, 1] max = myList[0] indexOfMax = 0 for i in range(1, len(myList)): if myList[i] > max: max = myList[i] indexOfMax = i

1

Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1.count(5)

2

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

2

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 [1, 3, 2], what is sum(list1)

6

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

8

_________ creates a list

A. list1 = list() B. list1 = [] C. list1 = list([12, 4, 4]) D. list1 = [12, 4, 4] E. list1 = [1, "3", "red"]

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

False

"Welcome to Python".split() is _____

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

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

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

What is list("abcd")?

['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]

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]

Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after list1.sort()?

[1, 3, 3, 4, 5, 5, 20, 25]

Suppose list1 is [1, 3, 2, 4, 5, 2, 1, 0], Which of the following is correct?

a. print(list1[0]) B. print(list1[:2]) C. print(list1[:-2]) D. print(list1[4:6])

To add 5 to the end of list1, use _

list1.append(5)

To insert 5 to the third position in list1, use _

list1.insert(3, 5)

To remove string "red" from list1, use _

list1.remove("red")

For the binarySearch function in Section 10.10.2, what is low and high after the first iteration of the while loop when invoking binarySearch([1, 4, 6, 8, 10, 15, 20], 11)?

low is 4 and high is 6

To shuffle list1, use _____

random.shuffle(list1)


Kaugnay na mga set ng pag-aaral

ATI Fundamentals for Nursing Edition 11.0

View Set

CSCI 301 10/17/2023 - Testing Oracle & Testing Coverage

View Set

APUSH FINAL 1st Semester (Packets of Practice Questions)

View Set

PHR FLASHCARDS ONWARD OPPORTUNITY

View Set