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 Final Exam V1 | D 522 Python for IT Automation | Actual Q&A with Rationale (D522 Final Exam) | Western Governors University

Document preview thumbnail
Preview 3 out of 28 pages

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

Content preview

D 522 Final Exam V1 | D 522 Python for IT
Automation | Actual Q&A with Rationale
(D522 Final Exam) | Western Governors
University
1. When using the regular expression module in Python, which function should be used to

find every instance of a pattern within a target string?

A. re.findall()


B. re.match()


C. re.search()


D. re.finditer()


Answer: A


Rationale: The re.findall() function is designed to scan the entire string and return all non-

overlapping matches as a list of strings. This is particularly useful in IT automation for

extracting all IP addresses or error codes from a large log file. Unlike re.search(), which

only returns the first match, findall ensures comprehensive data extraction.


2. Which keyword is used to ensure that a file is properly closed after its operations are

complete, even if an exception occurs?

A. with


B. open

,C. close


D. finally


Answer: A


Rationale: The ‘with’ statement in Python creates a context manager that automatically

handles resource cleanup. In the context of IT automation, using ‘with open()’ prevents file

corruption and memory leaks by ensuring the file closes after the block finishes. This is

considered a best practice over manually calling the .close() method.


3. What is the primary purpose of the ‘unittest’ module in a Python automation workflow?

A. To automate the deployment of scripts to production.


B. To verify that individual components of the script work as intended.


C. To create graphical user interfaces for system administrators.


D. To manage external library dependencies via pip.


Answer: B


Rationale: The unittest module provides a framework for creating automated tests to

validate that code behaves correctly. IT automation requires high reliability, so testing

individual functions helps prevent regressions when scripts are updated. It allows

developers to assert that outputs match expected values across various system

environments.

, 4. In the ‘subprocess’ module, which argument should be set to True to capture the output of

a system command for further processing?

A. check


B. shell


C. capture_output


D. text


Answer: C


Rationale: The capture_output=True argument allows the subprocess.run() function to

store the stdout and stderr of the command. This is essential for scripts that need to parse

the results of a shell command to make logic-based decisions. Without this, the output is

simply printed to the console and cannot be assigned to a Python variable.


5. Which logging level should be used for events that indicate an unexpected problem,

though the script is still able to continue running?

A. DEBUG


B. INFO


C. WARNING


D. CRITICAL


Answer: C

Document information

Uploaded on
July 16, 2026
Number of pages
28
Written in
2025/2026
Type
Exam (elaborations)
Contains
Questions & answers
$17.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