PCAP-31-03 Practice Test

Review 129 PCAP-31-03 practice questions with answer explanations and community insights.

Question 1

What is true about Python packages? (Choose two.)

  1. a code designed to initialize a package’s state should be placed inside a file named init.py
  2. a package’s contents can be stored and distributed as an mp3 file
  3. __pycache__ is a folder that stores semi-compiled Python modules
  4. the sys.path variable is a list of strings

Question 2

What is the expected output of the following code? import sys import math b1 = type(dir(math)) is list b2 = type(sys.path) is list print(b1 and b2)

  1. None
  2. True
  3. 0
  4. False

Question 3

A Python package named pypack includes a module named pymod.py which contains a function named pyfun(). Which of the following snippets will let you invoke the function? (Choose two.)

  1. from pypack.pymod import pyfun pyfun()
  2. import pypack pymod.pyfun()
  3. from pypack import * pyfun()
  4. import pypack import pypack.pymod pypack.pymod.pyfun()

Question 4

Assuming that the code below has been executed successfully, which of the following expressions will always evaluate to True? (Choose two.) import random v1 = random.random() v2 = random.random()

  1. len(random.sample([1,2,3],1)) > 2
  2. v1 == v2
  3. random.choice([1,2,3]) > 0
  4. v1>1

Question 5

With regards to the directory structure below, select the proper forms of the directives in order to import module_c. (Choose two.)

  1. from pypack.upper.lower import module_c
  2. import pypack.upper.lower.module_c
  3. import upper.module_c
  4. import upper.lower.module_c