




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A set of questions and answers designed to help individuals prepare for the pcap (certified associate in python programming) certification exam. The questions cover various aspects of python programming, including module imports, sys.path, random module functions, math module functions, built-in functions, package directories, and exception handling. Each question is followed by the correct answer and a brief explanation to enhance understanding and test preparation. This resource is valuable for students and professionals aiming to validate their python skills and knowledge.
Typology: Exams
1 / 185
This page cannot be seen from the preview
Don't miss anything!





























































































Question 1. Which of the following statements correctly imports only the sqrt function from the math module? A) import math.sqrt B) from math import sqrt C) import sqrt from math D) from math import * Answer: B Explanation: The syntax from math import sqrt imports only the sqrt function from the math module. Question 2. What does the sys.path variable contain? A) All built-in Python functions
B) List of directories Python searches for modules C) Current working directory D) List of all loaded modules Answer: B Explanation: sys.path is a list of strings indicating the search path for modules. Question 3. Which function in the random module returns a random element from a non-empty sequence? A) random() B) choice() C) sample()
Question 5. Which built-in function can be used to see all attributes of an imported module? A) list() B) dir() C) help() D) attributes() Answer: B Explanation: dir() lists all attributes and methods of an object or module.
Question 6. What is the purpose of the init.py file in a package directory? A) It is required to mark a directory as a Python package B) It stores initialization variables C) It is always empty D) It prevents importing modules Answer: A Explanation: init.py is needed to mark directories on disk as Python package directories. Question 7. Which statement about the pycache directory is true? A) It stores compiled bytecode of imported modules
Answer: D Explanation: When a script runs directly, name is set to 'main'. Question 9. How can you import a function from a nested module within a package? A) from package.module import function B) import module.function C) from module import package.function D) from package import function Answer: A Explanation: The correct way is from package.module import function.
Question 10. Which math module function returns the largest integer less than or equal to a number? A) ceil() B) floor() C) trunc() D) round() Answer: B Explanation: floor() returns the largest integer less than or equal to the input. Question 11. Which random module function can be used to get a list of unique random elements from a sequence?
D) The processor type Answer: A Explanation: platform.system() returns the name of the OS, such as 'Windows', 'Linux'. Question 13. Which of these will import and alias the random module as rnd? A) import random as rnd B) from random import rnd C) import rnd from random D) from random import random as rnd Answer: A
Explanation: import random as rnd renames the random module to rnd within the script. Question 14. What is the purpose of the dir() function when used on a module? A) Lists all modules B) Lists all attributes and functions C) Returns documentation D) Imports all functions Answer: B Explanation: dir(module) returns a list of names defined in the module.
B) sys.path C) search.path D) import.path Answer: B Explanation: sys.path is the list Python uses to find modules. Question 17. What does the math.trunc(3.9) function return? A) 4 B) 3 C) 3. D) 0
Answer: B Explanation: math.trunc() truncates the decimal part, returning just the integer. Question 18. Which random module function should you use to initialize the random number generator for reproducibility? A) random() B) seed() C) shuffle() D) sample() Answer: B Explanation: random.seed() initializes the random number generator.
A) A Python file with functions/class definitions B) A directory with init.py only C) A compiled C file D) A text file with no code Answer: A Explanation: A module is a Python file with code (functions, classes, etc.). Question 21. What is the convention for naming private variables in a module? A) Start with __ B) Start with _
C) End with __ D) Start with priv_ Answer: B Explanation: Variables starting with a single underscore (_) are considered private. Question 22. In a package, what is the effect of omitting init.py in a directory? A) Directory can't be imported as a package B) No effect C) Directory is deleted D) Only submodules can be imported
Question 24. How does Python search for modules when importing? A) In the current directory first, then sys.path B) Only in the standard library C) Only in user directories D) In pycache only Answer: A Explanation: Python searches the current directory, then the paths in sys.path. Question 25. What does except (ValueError, TypeError) do? A) Catches both ValueError and TypeError exceptions
B) Catches only TypeError C) Ignores both exceptions D) Raises ValueError Answer: A Explanation: The syntax catches either of the listed exceptions. Question 26. What happens if an exception isn't caught in Python? A) Program continues B) Program crashes and prints a traceback C) Exception is ignored D) Next exception is raised