D 522 Final Exam V2 | D 522 Python for IT
Automation | Actual Q&A with Rationale
(D522 Final Exam) | Western Governors
University
1. When automating file system tasks, which Python module is primarily used to interact with
the operating system for tasks like creating directories?
A. sys
B. subprocess
C. os
D. re
Answer: C
Rationale: The ‘os’ module provides a portable way of using operating system dependent
functionality. In IT automation, it is essential for directory management and environment
variable access. Utilizing this module allows scripts to run across different platforms
without changing the code for basic file system operations.
2. Which regular expression character is used to match zero or more occurrences of the
preceding character?
A. *
B. ?
,C. +
D. .
Answer: A
Rationale: The asterisk (*) quantifier matches zero or more repetitions of the preceding
element. This is a fundamental tool when searching for patterns in logs where a value
might be missing or repeated. Understanding quantifiers is critical for creating flexible
search patterns in Python scripting.
3. In the context of the ‘subprocess’ module, what is the purpose of setting
‘capture_output=True’?
A. To stop the script if the command fails
B. To prevent the command from running in the background
C. To store stdout and stderr in the returned object
D. To display the output directly to the terminal
Answer: C
Rationale: Setting ‘capture_output=True’ allows the Python script to intercept the text
printed by the external process. This enables the script to process the output data for
further logic or logging. It is a best practice for automation when the results of a system
command determine the next step in a workflow.
, 4. Which method is specifically used to convert a JSON-formatted string into a Python
dictionary?
A. json.loads()
B. json.load()
C. json.dumps()
D. json.dump()
Answer: A
Rationale: The ‘json.loads()’ function stands for ‘load string’, which parses a valid JSON
string into a Python object. This is distinct from ‘json.load()’, which reads from a file
pointer. Automating API interactions frequently requires this conversion to manipulate
web data within Python.
5. What is the primary advantage of using a ‘csv.DictReader’ over a standard ‘csv.reader’?
A. It executes much faster on large datasets
B. It automatically converts strings to integers
C. It maps the information in each row to a dictionary using header names
D. It removes duplicate entries from the CSV file
Answer: C
Rationale: The ‘csv.DictReader’ class creates a dictionary for each row where keys are the
column headers. This makes the code more readable and less prone to errors if the column
Automation | Actual Q&A with Rationale
(D522 Final Exam) | Western Governors
University
1. When automating file system tasks, which Python module is primarily used to interact with
the operating system for tasks like creating directories?
A. sys
B. subprocess
C. os
D. re
Answer: C
Rationale: The ‘os’ module provides a portable way of using operating system dependent
functionality. In IT automation, it is essential for directory management and environment
variable access. Utilizing this module allows scripts to run across different platforms
without changing the code for basic file system operations.
2. Which regular expression character is used to match zero or more occurrences of the
preceding character?
A. *
B. ?
,C. +
D. .
Answer: A
Rationale: The asterisk (*) quantifier matches zero or more repetitions of the preceding
element. This is a fundamental tool when searching for patterns in logs where a value
might be missing or repeated. Understanding quantifiers is critical for creating flexible
search patterns in Python scripting.
3. In the context of the ‘subprocess’ module, what is the purpose of setting
‘capture_output=True’?
A. To stop the script if the command fails
B. To prevent the command from running in the background
C. To store stdout and stderr in the returned object
D. To display the output directly to the terminal
Answer: C
Rationale: Setting ‘capture_output=True’ allows the Python script to intercept the text
printed by the external process. This enables the script to process the output data for
further logic or logging. It is a best practice for automation when the results of a system
command determine the next step in a workflow.
, 4. Which method is specifically used to convert a JSON-formatted string into a Python
dictionary?
A. json.loads()
B. json.load()
C. json.dumps()
D. json.dump()
Answer: A
Rationale: The ‘json.loads()’ function stands for ‘load string’, which parses a valid JSON
string into a Python object. This is distinct from ‘json.load()’, which reads from a file
pointer. Automating API interactions frequently requires this conversion to manipulate
web data within Python.
5. What is the primary advantage of using a ‘csv.DictReader’ over a standard ‘csv.reader’?
A. It executes much faster on large datasets
B. It automatically converts strings to integers
C. It maps the information in each row to a dictionary using header names
D. It removes duplicate entries from the CSV file
Answer: C
Rationale: The ‘csv.DictReader’ class creates a dictionary for each row where keys are the
column headers. This makes the code more readable and less prone to errors if the column