Python- Multiple Choice (MCQ)

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

What is the output of the following? try: if '1' != 1: raise "someError" else: print("someError has not occured") except "someError": print ("someError has occured") a) someError has occured b) someError has not occured c) invalid code d) none of the above

C A new exception class must inherit from a BaseException. There is no such inheritance here.

What is the maximum possible length of an identifier? a) 31 characters b) 63 characters c) 79 characters d) None of the above

D

Why are local variable names beginning with an underscore discouraged? a) they are used to indicate a private variables of a class b) they confuse the interpreter c) they are used to indicate global variables d) they slow down execution

a

What is the output of the following? f = None for i in range (5): with open("data.txt", "w") as f: if i > 2: break print f.closed a) True b) False c) None d) Error

a) True The WITH statement when used with open file guarantees that the file object is closed when the with block exits.

Which of the following is an invalid statement? a) abc = 1,000,000 b) a b c = 1000 2000 3000 c) a,b,c = 1000, 2000, 3000 d) a_b_c = 1,000,000

b)

Which one of these is floor division? a) / b) // c) % d) None of the mentioned

b) //

To open a file c:scores.txt for writing, we use a) outfile = open("c:scores.txt", "r") b) outfile = open("c:scores.txt", "w") c) outfile = open(file = "c:scores.txt", "r") d) outfile = open(file = "c:scores.txt", "o")

b) The location contains double slashes ( ) and w is used to indicate that file is being written to.

Which of the following statements create a dictionary? (Multiple Correct Answers Possible) a) d = {} b) d = {"john":40, "peter":45} c) d = {40:"john", 45:"peter"} d) d = (40:"john", 45:"50")

b, c & d.

Suppose list1 is [2, 33, 222, 14, 25], What is list1[-1] ? a) Error b) None c) 25 d) 2

c) 25 The index -1 corresponds to the last index in the list.

When will the else part of try-except-else be executed? a) always b) when an exception occurs c) when no exception occurs d) when an exception occurs into except block

c) when no exception occurs The else part is executed when no exception occurs.


Kaugnay na mga set ng pag-aaral

IELTS words, Proficiency Unit 10, CPE wordlist, Cambridge CPE, CPE Unit 9, CPE Unit8, CPE Unit 7, CPE, CPE Unit 10

View Set

Knowledge of Capital Markets - Market Structure

View Set

Chapter 9 - Enzymes: Regulation of Activities

View Set

Ch. 16 Integrated Marketing Communication

View Set