Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Document preview thumbnail
Preview 3 out of 28 pages
Exam (elaborations)

D 522 Exam 2 V2 | D 522 Python for IT Automation | Actual Q&A with Rationale (D522 Exam 2) | Western Governors University

Document preview thumbnail
Preview 3 out of 28 pages

D 522 Exam 2 V2 | D 522 Python for IT Automation | Actual Q&A with Rationale (D522 Exam 2) | Western Governors University

Content preview

D 522 Exam 2 V2 | D 522 Python for IT
Automation | Actual Q&A with Rationale
(D522 Exam 2) | Western Governors
University
1. When using the subprocess module, which parameter of the run() function is required to

capture the standard output of a command so it can be accessed in the script?

A. shell=True


B. check=True


C. capture_output=True


D. timeout=10


Answer: C


Rationale: The capture_output parameter is essential when the script needs to process the

result of a system command. When set to True, both stdout and stderr are captured and

stored in the returned CompletedProcess object. This allows the developer to read the

command’s response rather than just seeing it printed to the terminal.


2. In the context of Regular Expressions, what is the purpose of the ‘?’ quantifier?

A. Matches zero or more occurrences


B. Matches one or more occurrences


C. Matches exactly one occurrence

,D. Matches zero or one occurrence


Answer: D


Rationale: The question mark in a regex pattern signifies that the preceding character or

group is optional. This means it matches either zero or one instance of that specific

element. It is frequently used for handling optional characters like the ‘s’ in ‘https’ or

optional punctuation.


3. Which function from the ‘os’ module should be used to combine directory paths in a way

that is portable across different operating systems?

A. os.path.combine()


B. os.path.merge()


C. os.path.join()


D. os.path.add()


Answer: C


Rationale: The os.path.join function intelligently concatenates path segments using the

correct separator for the host operating system. This prevents errors that occur when

hardcoding forward or backward slashes into script strings. Utilizing this function ensures

that automation scripts remain functional on both Linux and Windows environments.


4. What is the primary difference between the ‘r+’ and ‘w+’ file opening modes in Python?

A. ‘r+’ creates a new file if it does not exist, while ‘w+’ does not.

, B. ‘w+’ truncates the file to zero length if it exists, while ‘r+’ does not.


C. ‘r+’ is for binary files and ‘w+’ is for text files.


D. There is no difference between the two modes.


Answer: B


Rationale: The ‘r+’ mode opens a file for both reading and writing without erasing the

existing content. In contrast, ‘w+’ also allows reading and writing but will overwrite any

existing file content immediately upon opening. Understanding this distinction is critical

for data integrity when automating file updates.


5. When writing unit tests using the ‘unittest’ framework, which method is used to verify that

two values are the same?

A. self.checkEqual()


B. self.assertMatch()


C. self.verify()


D. self.assertEqual()


Answer: D


Rationale: The assertEqual method is the standard way to check for equality within a test

case class. If the two provided arguments are not equal, the test will fail and report the

discrepancy. This is a fundamental tool for verifying that automation logic produces the

expected output values.

Document information

Uploaded on
July 16, 2026
Number of pages
28
Written in
2025/2026
Type
Exam (elaborations)
Contains
Questions & answers
$16.99

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
ScholarsAscend
3.7
(77)
Sold
453
Followers
39
Items
29361
Last sold
11 hours ago




Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions