Python Essentials 2_Part 2 Summary Test

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

What is the expected output of the following code? class A: def __init__(self, v=2): self.v = v def set(self, v=1): self.v += v return self.v a = A() b = a b.set() print(a.v) A) 1 B) 0 C) 2 D) 3

Answer: D

What output will appear after running the following snippet? A) The number of all the entities residing in the math module B) A string containing the fully qualified name of the module C) An error message D) A list of all the entities residing in the math module

Answer: D

Which pip command would you use to uninstall a previously install package? A) pip delete *packagename* B) pip -uninstall *packagename* C) pip -remove *packagename* D) pip uninstall *packagename*

Answer: D

Assuming that the following three files a.py, and c.py reside in the same directory, what will be the output produced after running the c.py file? python # file a.py print("a", end="") # file b.py import a print("b", end="") # file c.py print("c", end="") import a import b a. cab b. cab c. abc d. bac

Answer: a

Look at the following code: python numbers = [i*i for i in range(5)] # Insert line of code here. print(foo) Which line would you insert in order for the program to produce the expected output? python [1, 9] a. foo = list(filter(lambda x: x % 2, numbers)) b. foo = list(filter(lambda x: x / 2, numbers)) c. foo = list(map(lambda x: x % 2, numbers)) d. foo = list(map(lambda x: x // 2, numbers))

Answer: a

What is the expected result of executing the following code? python def o(p): def q(): return "*" * p return q r = o(1) s = o(2) print(r() + s()) a. The code will print *** b. The code will print **** c. The code will print * d. The code will print **

Answer: a

What is the expected result of the following snippet? python try: raise Exception except: print("c") except BaseException: print("a") except Exception: print("b") a. The code will cause a syntax error b. 1 c. b d. a

Answer: a

Assuming that the​ open() invocation has gone successfully, the following snippet: python for x in open("file", "rt")): print(x) will: a. read the file character by character b. read the file line by line c. read the whole file at once d. cause an exception

Answer: b

What is the expected result of executing the following code? python class A: def __init__(self): pass a = A(1) print(hasattr(a, "A")) a. The code will print 1 b. The code will raise an exception c. The code will print False d. The code will print True

Answer: b

Which of the following commands would you use to check pip"s version? (Select two answers) a. pip version b. pip --version c. pip-version d. pip3 --version

Answer: b, d

If the class constructor is declared in the following way: python class Class: def __init__(self, vla = 0): pass which one of the assignments is invalid? a. object = Class(1) b. object = Class(None) c. object = Class(1, 2) d. object = Class()

Answer: c

The following line of code: python for line in open("text.txt", "rt"): a. in invalid because open returns nothing b. is invalid because open returns a non-iterable object c. is invalid because open returns an iterable object d. may be valid if line is a list

Answer: c

What will be the output of the following code, located in the p.py file? python print(__name__) a. main b. p.py c. __main__ d. __p.py__

Answer: c

If a is a stream opened in read mod, the following line: python q = s.read(1) will read: a. one line from the stream b. one kilobyte from the stream c. one buffer from the stream d. one character from the stream

Answer: d

The following code: python x = " \\" print(len(x)) a. will print 1 b. will print 3 c. will print 2 d. will cause an error

Answer: d

The following statement: python from a.b import c causes the import of: a. entity a from module b from package c b. entity b from module a from package c c. entity c from module a from package b d. entity c from module b from package a

Answer: d

The sys.stderr stream is normally associated with: a. the keyboard b. the printer c. a null device d. the screen

Answer: d

What is the expected result of the following code? python def my_fun(n): s = "+" for i in range(n): s += s yield s for x in my_fun(2): print(x, end="") a. The code will print + b. The code will print +++ c. The code will print ++ d. The code will print ++++++

Answer: d

What is the expected result of the following code? python import os os.mkdir("pictures") os.chdir("pictures") print(os.getcwd()) a. The code will print the owner of the created directory b. The code will print the content of the created directory c. The code will print the name of the created directory d. The code will print the path to the created directory

Answer: d

What is the expected output of the following code? class A: A = 1 def __init__(self): self.a = 0 print(hasattr(A, "a")) A) 0 B) True C) 1 D) False

Answer: D

Look at the code below: import random # # Insert lines of code here. # print(a, b, c) Which lines of code would you insert so that it is possible for the program to output the following result: 6 82 0 A) a = random.randint(0, 100) b = random.randrange(10, 100, 3) c = random.choice((0, 100, 3)) B) a = random.choice((0, 100, 3)) b = random.randrange(10, 100, 3) c = random.randint(0, 100) C) a = random.randrange(10, 100, 3) b = random.randint(0, 100) c = random.choice((0, 100, 3)) D) a = random.randint(0, 100) b = random.choice((0, 100, 3)) c = random.randrange(10, 100, 3)

Answer: A

The following code: print(float("1.3")) A) will print 1.3 B) will print 13 C) will print 1,3 D) will raise a ValueError exception

Answer: A

What is the expected effect of running the following code? class A: def __init__(self, v): self.__a = v + 1 a = A(0) print(a.__a) A) The code will raise an AttributeError exception B) The code will print 2 C) The code will print 0 D) The code will print 1

Answer: A

What is the expected result of the following code? from datetime import timedelta delta = timedelta(weeks = 1, days = 7, hours = 11) print(delta * 2) A) 28 days, 22:00:00 B) 2 weeks, 14 days, 22 hours C) 7 days, 22:00:00 D) The code will raise an exception

Answer: A

The following code: x = "\\\\" print(len(x)) A) will print 1 B) will print 2 C) will cause an error D) will print 3

Answer: B

What is the excepted result of the following snippet? try: raise Exception except BaseException: print("a") except Exception: print("b") except: print("c") A) b B) a C) An error message D) 1

Answer: B

What is the expected result of executing the following code? class I: def __init__(self): self.s = "abc" self.i = 0 def __init__(self): return self def __next__(self): if self.i == len(self.s): raise StopIteration v = self.s[self.i] self.i += 1 return v for x in I(): print(x, end="") A) The code will print 210 B) The code will print abc C) The code will print 012 D) The code will print cba

Answer: B

What is the expected result of the following code? import calendar calendar.setfirstweekday(calendar.SUNDAY) print(calendar.weekheader(3)) A) Su Mo Tu We Th We Fr Sa B) Sun Mon Tue Wed Thu Fri Sat C) Tu D) Tue

Answer: B

If there are more than one except: branch after the try: clause, we can say that: A) exactly one except: block will be executed B) one or more except: blocks will be executed C) not more than one except: block will be executed D) none of the except: blocks will be executed

Answer: C

Knowing that a function named fun() resides in a module named mod, and was imported using the following statement: from mod import fun Choose the right way to invoke the fun() function: A) mod:fun() B) mod::fun() C) fun() D) mod.fun()

Answer: C

The following code: print(chr(ord("p") + 2)) will print: A) q B) s C) r D) t

Answer: C

The following statement: assert var != 0 A) is erroneous B) has no effect C) will stop the program when var == 0 D) will stop the program when var != 0

Answer: C

What is the excepted result of executing the following code? try: raise Exception(1, 2, 3) except Exception as e: print(len(e.args)) A) The code will raise an unhandled exception B) The code will print 2 C) The code will print 3 D) The code will print 1

Answer: C

What is the expected result of executing the following code? class A: pass class B(A): pass class C(B): pass print(issubclass(A, C)) A) The code will print True B) The code will print 1 C) The code will print False D) The code will raise an exception

Answer: C

What is the expected result of executing the following code? class A: def a(self): print("a") class B: def a(self): print("b") class C(B, A): def c(self): self.a() o = C() o.c() A) The code will print c B) The code will raise an exception C) The code will print b D) The code will print a

Answer: C

What is the expected result of the following code? from datetime import datetime datetime_1 = datetime(2019, 11, 27, 11, 27, 22) datetime_2 = datetime(2019, 11, 27, 0, 0, 0) print(datetime_1 - datetime_2) A) 0 days B) 0 days, 11:27:22 C) 11:27:22 D) 11 hours, 27 minutes, 22 seconds

Answer: C

What information can be read using the uname function provided by the os module? (Select two answers) import os os.mkdir("pictures") os.chdir("pictures") print(os.getcwd()) A) Last login date. B) Current path C) Operating system name D) Hardware identifier

Answer: C, D

If you want to fill a byte array with data read in from a stream, which method you can use? A) The read() method B) The readbytes() method C) The readfrom() method D) The readinto() method

Answer: D

Look at the following code: numbers = [0, 2, 7, 9, 10] # Insert line of code here. print(list(foo)) Which line would you insert in order for the program to produce the expected output? [0, 4, 49, 81, 100] A) foo = lambda num: num ** 2, numbers B) foo = lambda num: num * 2, numbers C) foo = filter(lambda num: num ** 2, numbers) D) foo = map(lambda num : num ** 2, numbers)

Answer: D

The compiled Python bytecode is stored in files which have their names ending with: A) py B) pyb C) pc D) pyc

Answer: D


संबंधित स्टडी सेट्स

Series 7: Taxes and Tax Shelters (Tax Advantaged Investments)

View Set

Audit 439: Chapters 10-14 HW Answers

View Set

W History H Chapter 4 Vocab and Notes

View Set

Linux+ XK0-004 - Practice Questions from Book

View Set

12.35.F - Quiz: 12.35.M - 12.35.R (Includes Optional Quiz Review Materials)

View Set

Associate Contractors License Exam

View Set

Chapter 3: Creating Anglo-America, 1660-1750

View Set