Docsity

PCAP Certified Associate in Python Programming Exam Questions, Exams of Technology

Toggle sidebar
bg1
PCAP 31 03 PCAP Certified Associate
in Python Programming Exam
Question 1. Which statement properly imports the sqrt function from
the math module?
A) import sqrt
B) import math.sqrt
C) from math import sqrt
D) from sqrt import math
Answer: C
Explanation: "from math import sqrt" imports only the sqrt function
from the math module.
Question 2. What does "import math as m" allow you to do?
A) Use m instead of math to access module functions
B) Import only some functions from math
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download PCAP Certified Associate in Python Programming Exam Questions and more Exams Technology in PDF only on Docsity!

in Python Programming Exam

Question 1. Which statement properly imports the sqrt function from the math module? A) import sqrt B) import math.sqrt C) from math import sqrt D) from sqrt import math Answer: C Explanation: "from math import sqrt" imports only the sqrt function from the math module. Question 2. What does "import math as m" allow you to do? A) Use m instead of math to access module functions B) Import only some functions from math

in Python Programming Exam

C) Rename math functions D) Import math as a string Answer: A Explanation: "import math as m" allows you to refer to the math module as "m" in your code. Question 3. Which of the following will import all public names from the random module? A) import random.all B) from random import * C) random import * D) import * from random Answer: B

in Python Programming Exam

Question 5. What does the dir() function do when used with a module? A) Deletes the module B) Lists all attributes and functions defined in the module C) Imports another module D) Returns the file path Answer: B Explanation: dir() lists the names defined in a module. Question 6. Which variable affects the list of directories Python searches for modules? A) os.environ B) sys.argv

in Python Programming Exam

C) sys.path D) path.sys Answer: C Explanation: sys.path is a list of directory names that Python searches for modules. Question 7. What is the output of math.ceil(4.2)? A) 4 B) 5 C) 4. D) 3 Answer: B

in Python Programming Exam

Question 9. What is the purpose of math.trunc(5.99)? A) Rounds to the nearest integer B) Drops the decimal part, returning 5 C) Rounds up D) Returns 6 Answer: B Explanation: math.trunc removes the decimal part without rounding. Question 10. What will math.factorial(5) return? A) 5 B) 25 C) 120

in Python Programming Exam

D) 15

Answer: C Explanation: The factorial of 5 is 5Ɨ4Ɨ3Ɨ2Ɨ1 = 120. Question 11. What does random.seed(10) do? A) Sets the range of random numbers B) Changes the random number algorithm C) Initializes the random number generator for reproducibility D) Increases randomness Answer: C Explanation: random.seed initializes the generator to produce the same sequence of random numbers.

in Python Programming Exam

B) random.item(lst) C) random.choice(lst) D) lst.random() Answer: C Explanation: random.choice() picks a random item from a sequence. Question 14. What does random.sample([1, 2, 3, 4], 2) do? A) Returns two random unique elements from the list B) Returns all elements shuffled C) Returns a random integer D) Returns the first 2 elements Answer: A

in Python Programming Exam

Explanation: random.sample returns k unique elements from the population. Question 15. Which function from the platform module returns the system's name (e.g., 'Windows', 'Linux')? A) platform.system() B) platform.machine() C) platform.processor() D) platform.version() Answer: A Explanation: platform.system() returns the OS type. Question 16. What does platform.machine() return?

in Python Programming Exam

D) platform.machine() Answer: B Explanation: platform.python_implementation() gives the Python implementation name. Question 18. How do you create a user-defined module? A) By writing code in a .txt file B) By writing code in a .py file C) By creating a folder named module D) By using the import statement Answer: B Explanation: User-defined modules are created by writing code in .py files.

in Python Programming Exam

Question 19. What is the purpose of the pycache directory? A) To store source code B) To store compiled bytecode of Python modules C) To store logs D) To store package names Answer: B Explanation: pycache stores the compiled bytecode files. Question 20. What is the value of name when a module is run directly? A) 'imported'

in Python Programming Exam

Answer: B Explanation: name is set to the module's name during import. Question 22. What is the purpose of prefixing an attribute with a single underscore (e.g., _var)? A) Makes it public B) Denotes a private or internal-use variable by convention C) Makes it global D) Makes it static Answer: B Explanation: A single underscore indicates intended internal use (not enforced).

in Python Programming Exam

Question 23. What does double underscore (e.g., __var) trigger in Python classes? A) Private variable (with name mangling) B) Static variable C) Public variable D) Protected variable Answer: A Explanation: Double underscores trigger name mangling for pseudo- private variables. Question 24. What is the main role of the init.py file in a package? A) To define the package's public interface B) To store bytecode

in Python Programming Exam

Explanation: Only directories containing init.py are recognized as packages. Question 26. Which syntax allows importing a nested module named submod in package pkg? A) import pkg.submod B) import submod.pkg C) from pkg import submod D) Both A and C Answer: D Explanation: Both "import pkg.submod" and "from pkg import submod" are valid.

in Python Programming Exam

Question 27. What does the statement "from. import submodule" do inside a package? A) Imports submodule from the current package B) Imports from parent package C) Imports from system path D) Causes syntax error Answer: A Explanation: A leading dot indicates a relative import from the current package. Question 28. How does Python distinguish nested packages from simple directory trees? A) By the presence of .py files