• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 3 out of 28 pages
Exam (elaborations)

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

Content preview

D 522 Final Exam V2 | D 522 Python for IT
Automation | Actual Q&A with Rationale (D522
Final Exam) | Western Governors University
1. Which module in Python is most commonly used for executing external commands and

capturing their output in an automation script?

A. sys


B. os.path


C. subprocess


D. shutil


Correct Answer: C


Explanation: The subprocess module allows you to spawn new processes and connect to

their input/output/error pipes. It is the recommended replacement for older functions like

os.system. Using subprocess.run() provides a high-level interface for most automation

tasks requiring command-line execution.


2. In the context of regular expressions, which character is used to match one or more

occurrences of the preceding character?

A. ?


B. Plus (+)


C. {

,D. .


Correct Answer: B


Explanation: The plus sign (+) is a quantifier in regular expressions that matches one or

more repetitions. It ensures that the preceding element appears at least once in the target

string. This is distinct from the asterisk (*), which matches zero or more occurrences.


3. What does the ‘sys.argv[0]’ represent when a Python script is executed from the command

line?

A. The first argument passed to the script


B. The current working directory


C. The total number of arguments


D. The name of the script itself


Correct Answer: D


Explanation: In Python, sys.argv is a list containing the command-line arguments passed

to the script. The element at index 0 is always the path or filename of the script being run.

Subsequent arguments provided by the user occupy indices 1 and higher.


4. Which method is used in the ‘unittest’ framework to verify that a specific exception is

raised by a piece of code?

A. expectException()


B. assertError()

, C. assertRaises()


D. checkFailure()


Correct Answer: C


Explanation: The assertRaises() method is used within unit tests to confirm that a block of

code triggers a designated exception. It is often used as a context manager with the ‘with’

statement for clarity. Testing for expected failures is a critical component of robust

automation scripting.


5. When opening a file for logging purposes where new entries should be added to the end

without deleting existing content, which mode should be used?

A. ‘w’


B. ‘r+’


C. ‘a’


D. ‘x’


Correct Answer: C


Explanation: The ‘a’ mode stands for ‘append,’ which opens a file and places the cursor at

the end for writing. If the file does not exist, it will be created automatically. This is

essential for log files to ensure previous data is preserved while adding new information.

Document information

Uploaded on
September 24, 2026
Number of pages
28
Written in
2026/2027
Type
Exam (elaborations)
Contains
Questions & answers
$19.38

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.
Shinnie
3.6
(7)
Sold
27
Followers
0
Items
4868
Last sold
1 week 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