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

Content preview

D 522 Final Exam V3 | D 522 Python for IT
Automation | Actual Q&A with Rationale
(D522 Final Exam) | Western Governors
University
1. Which function from the ‘os’ module is used to check if a specific file or directory path

currently exists on the system?

A. os.path.isfile()


B. os.path.exists()


C. os.access()


D. os.path.isdir()


Answer: B


Rationale: The os.path.exists() function is the primary tool for verifying the presence of a

file or directory at a given path. It returns True if the path is valid and False if the location

does not exist. This is a fundamental check in automation to prevent execution errors when

resources are missing.


2. In the ‘sys’ module, what information is typically stored at index 0 of the ‘sys.argv’ list?

A. The first command-line argument provided by the user


B. The name of the script being executed


C. The total number of arguments passed to the script

,D. The current working directory of the process


Answer: B


Rationale: In Python, sys.argv[0] contains the name of the script that is currently running.

All subsequent elements in the list represent the additional arguments passed via the

terminal. Understanding this indexing is crucial for parsing user input correctly in CLI

automation tools.


3. When using the ‘re’ module, which method should be used to find all occurrences of a

pattern within a string and return them as a list?

A. re.search()


B. re.findall()


C. re.match()


D. re.finditer()


Answer: B


Rationale: The re.findall() method scans the entire string and extracts every substring that

matches the provided regular expression. Unlike re.search(), which only finds the first

match, findall() compiles every instance into a list. This is particularly useful for log parsing

when multiple entries need to be analyzed.


4. Which parameter in ‘subprocess.run()’ must be set to True to capture the output of a

command so it can be stored in a variable?

A. shell

, B. check


C. text


D. capture_output


Answer: D


Rationale: The capture_output parameter tells Python to redirect standard output and

standard error into the CompletedProcess object. By setting this to True, developers can

access the result using the .stdout attribute. Without this parameter, the command output

would simply print to the console instead of being saved.


5. What is the result of opening a file in ‘a’ mode (append mode) and writing data to it?

A. The existing contents of the file are deleted and replaced


B. A new file is created only if the file does not already exist


C. The file is opened for reading and writing simultaneously


D. The new data is added to the end of the existing file content


Answer: D


Rationale: Append mode (‘a’) ensures that any data written to the file is placed at the very

end of the existing content. Unlike write mode (‘w’), it does not truncate or clear the file

before writing. This is the standard mode used for generating continuous logs in

automation workflows.

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