IST 483

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

Consider the following code segment: x = values[0] for i in range(1, len(values)) : if values[i] > x : x = values[i] Which of the following statements assigns the same value to x as the code segment above? A. x = max(values) B. x = min(values) C. x = sum(values) D. x = sorted(values)

A

What is the resulting content of the list letters after this code snippet? letters = list("abcdefg") A. letters contains a list with the contents: ["a", "b", "c", "d", "e", "f", "g"] B. letters contains a list with the contents: ["abcdefg"] C. Invalid Type Error D. letters contains a list with the contents: ("abcdefg")

A

What will happen when the following code segment is executed? values = [1.618, 2.71, 3.14] print(values[3]) A. Python will display an out-of-range error B. Python won't display anything C. Python will display 3 D. Python will display 3.14

A

Given the following code snippet, which statement correctly creates an alias for the list prices? prices = [10.00, 15.50, 13.25, 20.15] A. values[10] = prices B. values = prices C. for element in prices : values = element D. values[10] = prices[10]

B

Given the following list, what value is at index 5? values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] A. 5 B. 6 C. 7 D. 4

B

Which of the following statements looks for the name 'Bob' in the list names? A. if "Bob" found in names : print("found Bob") B. if "Bob" in names : print("found Bob") C. if names contains "Bob" : print("found Bob") D. if names.indexOf("Bob") >= 0 : print("found Bob")

B

Which statement gets the length of the list values? A. numValues = length(values) B. numValues = len(values) C. numValues = size(values) D. numValues = values.length

B

Consider the following code segment: values = [1, 2, 3, 4, 5] moreValues = values moreValues[3] = 6 print(values) What is displayed when it runs? A. [1, 2, 3, 4, 5] B. [1, 2, 6, 4, 5] C. [1, 2, 3, 6, 5] D. [1, 2, 3, 4, 5, 6]

C

What is the difference between a list and a string? A. lists are sequences but strings are not and therefore you cannot access a string element using [] B. lists are immutable, but strings can be changed C. lists can hold values of any type, whereas strings are only sequences of characters D. elements in a list can be accessed using an integer as the index value, but strings can use any numeric data type for the index

C

What is the value of names after the following code segment has run? names = [] names.append("Amy") names.append("Bob") names.append("Peg") names[0] = "Cy" names.insert(0, "Ravi") A. ['Ravi', 'Cy', 'Amy', 'Bob', 'Peg'] B. ['Cy', 'Amy', 'Bob', 'Peg'] C. ['Ravi', 'Cy', 'Bob', 'Peg'] D. ['Ravi', 'Amy', 'Bob', 'Peg']

C

Which statement correctly creates a list that contains four elements? A. values[4] B. values = [4] C. values = [1, 2, 3, 4] D. value[4] = [1, 2, 3, 4]

C

Examine the code shown in the page 6 of the lecture slide 5 (video lecture @14:30). If the input for the problem is as follows: tswift = ((2014, "Katy"), (2014, "Harry"), (2008,"Harry")) the program will output: * Note: Very good code example; analyze this code line by line. Similar problem will be on the final exam. A. From 2008 to 2014 Taylor Swift wrote song about 3 people! B. From 2008 to 2008 Taylor Swifts wrote song abut 2 people! C. From 2008 to 2008 Taylor Swifts wrote song abut 1 people! D. From 2008 to 20014 Taylor Swifts wrote song abut 2 people!

D

Given a list values that contains the first ten prime numbers, which statement does NOT print each element in the list? A. for i in range(len(values)) : print(values[i]) B. for element in values : print(element) C. for i in range(0, len(values)) : print(values[i]) D. for i in range(1, len(values)) : print(values[i])

D

Given the definition of a list: names = [] which statement correctly adds "Harry" to the list? A. names[] = "Harry" B. names[len(names) + 1] = "Harry" C. names.add("Harry") D. names.append("Harry")

D

What is the resulting content of the list values after this code snippet? values = [1991, 1875, 1980, 1965, 2000] values.sort() A. [1991, 1875, 1980, 1965, 2000] B. [2000, 1991, 1980, 1965, 1875] C. [2000, 1991, 1875, 1980, 1965] D. [1875, 1965, 1980, 1991, 2000]

D

In Python, lists are immutable: T or F

F

In Python, tuples are mutable: T or F

F

L1 = [1,2] L2 = [3,4] L3 = L1 + L2 L1.extend([1,2]) print (L3) The output of the above code snippet is: [1,2,3,4,1,2] T or F

F


Kaugnay na mga set ng pag-aaral

Chapter 25: Assessment of Cardiovascular Function

View Set

3.32 Unit Test: Cell Biology - Part 1

View Set

Elasticity- price elasticity of demand

View Set

ISDS 1100 - Exam 1 Module 3, ISDS 1100 - Exam 1 Module 1, ISDS 1100 - Exam 1 Module 2

View Set

Part 2: Chpt. 24-24.3: Metabolism is the sum of all biochemical reactions in the body

View Set