CNIT 155 Final Exam In class exercises VLAB

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

What is the output when the following code is executed? 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 print(indexOfMax) A. 1 B. 2 C. 3 D. 4

A. 1

Suppose listExample is ['h','e','l','l','o'], what is len(listExample)? A. 5 B. 4 C. Error D. -1

A. 5

What's the output of the following code? def main(): try: test() print("Call complete.") except ZeroDivisionError: print("Divided by zero.") except: print("Exception.") def test(): y = x main() A. Exception. B. Call complete. C. Divided by zero. D. Divided by zero. Exception.

A. Exception.

The last element of a list called s is at position len(s) - 1. A. True B. False

A. True

The list can have duplicated elements A. True B. False

A. True

What is the value stored in L when the following code is executed? X= "Welcome to Python" L=X.split() A. ["Welcome", "to", "Python"] B. {"Welcome", "to", "Python"} C. "Welcome", "to", "Python" D. "WelcometoPython"

A. ["Welcome", "to", "Python"]

The readline() method returns a ____________. A. string B. a list which contains a single string C. a list of single characters D. a list of integers

A. string

Given a string s = "Programming is fun", what is s.find("rom")? A. 1 B. 3 C. -1 D. 4

C. -1

What is the output when following code is executed? 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 = " ") A. 2 3 4 5 6 1 B. 6 1 2 3 4 5 C. 2 3 4 5 6 6 D. 1 1 2 3 4 5

C. 2 3 4 5 6 6

What is the output of the below program? def printMax(a, b): if a > b: print(a, 'is maximum') elif a == b: print(a, 'is equal to', b) else: print(b, 'is maximum') #Call the function printMax(3, 4) A. 3 B. 4 C. 4 is maximum D. 2

C. 4 is maximum

What is the name of the error that will occur when your program is doing a "Division by zero" A. Syntax Error B. Semantic Error C. Run-Time Error D. Logical Error

C. Run-Time Error

What is the output when the following function is called as below? def f(values): values[0] = 44 # Call the above function as below v = [1, 2, 3] f(v) print(v) A. [1, 44] B. [1, 2, 3, 44] C. [44, 2, 3] D. [1, 2, 3]

C. [44, 2, 3]

Which of the following statement adds "Purdue University" to the end of a file referenced with the variable schools? schools = open("schools.txt", "a+") # other statements ...... name = "Purdue University" A. schools.append(name) B. schools.write("name"). C. schools.write(name) D. name.write(schools)

C. schools.write(name)

When reading a file using a file object, what method is best for reading the entire file into a single string? A. .read_file_to_str() B. .readlines() C. .readline() D. .read()

D. .read()

Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1.count(5)? A. 0 B. 4 C. 1 D. 2

D. 2

Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1.index(5)? A. 0 B. 4 C. 1 D. 2

D. 2

What is the output of the following code : L = ['a','b','c','d'] print ("".join(L)) A. Error B. None C. abcd D. ['a','b','c','d']

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

Every element in a list must have the same type? A. True B. False

B. False

Python lists are immutable, but strings are mutable A. True B. False

B. False

The return type of the readlines() in File class is a _______. A. a string B. a list of strings C. a list of lists D. a list of integers

B. a list of strings

When reading a file using the file object, which method reads the entire file into a single string? A. infile.read(2) B. infile.read() C. infile.readline() D. infile.readlines()

B. infile.read()

To insert 5 to the third position in list1, use _______. A. list1.insert(3, 5) B. list1.insert(2, 5) C. list1.add(3, 5) D. list1.append(3, 5)

B. list1.insert(2, 5)

Which of the following statement is used to open a file called names.txt in read-only mode? A. namesfile = open(names.txt, "w") B. namesfile = open("names.txt", "r") C. namesfile = open("names.txt", "b")

namesfile = open("names.txt", "r")


Kaugnay na mga set ng pag-aaral

Cloud Academy KC: Cloud Concepts (CLF-C01)

View Set

AP US Government Chapter 4 AP Classroom MCQ

View Set

SCDC Practice Test 1211 (Questions)

View Set

TEST #5 TEST BANK WONG CH 27 The Child with Cerebral Dysfunction

View Set