PCAP - Quizzes Summary Test 2 Answers
PCAP - Quizzes Summary Test 2 Answers
PCAP - Quizzes Summary Test 2 Answers
1. Knowing that a function named f() resides in a module named m, and was imported using the following statement
from mod import fun
choose the right way to invoke it:
fun()
mod.fun()
mod::fun()
mod:fun()
2. What output will appear after running the following snippet?
import math
print(dir(math))
an error message
a string containing the fully qualified name of the module
a list of all the entities residing in the math module
the number of all the entities residing in the math module
3. The compiled Python bytecode is stored in files having names ending with:
py
pyb
pc
pyc
4. Assuming that all three files, a.py, b.py, and c.py reside in the same folder, what will be the output produced by
running the c.py file?
# file a.py
print(“a”,end=”)
#file b.py
import a
print(“b”,end=”)
#file c.py
print(“c”,end=”)
import a
import b
cba
abc
bac
cab
5. What will be the output of the following code, located in file p.py?
print(__name__)
p.py
main
__p.py__
__main__
6. The following statement
from a.b import c
causes the import of:
entity a from module b from package c
entity b from module a from package c
entity c from module b from package a
entity c from module a from package b
7. If there are more than one except: branches after the try:, we can say that:
one or more of the try: blocks will be executed
none of the try: blocks will be executed
not more than one try: block will be executed
exactly one of the try: blocks will be executed
8. What will be the output of the following snippet? try: raise Exception
except BaseException:
print(“a”)
except Exception:
print(“b”)
except:
print(“c”)
c
b
it will cause an error
a
9. The following line of code: