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
Exam (elaborations)

WGU D522 Python for IT Automation ACTUAL OBJECTIVE ASSESSMENT PRACTICE 2026/2027 | Verified Code-Centric & Scenario-Based Questions and Answers | Grade A Target | Pass Guaranteed

Rating
-
Sold
-
Pages
30
Grade
A+
Uploaded on
07-02-2026
Written in
2025/2026

WGU D522 Python for IT Automation ACTUAL OBJECTIVE ASSESSMENT PRACTICE 2026/2027 | Verified Code-Centric & Scenario-Based Questions and Answers | Grade A Target | Pass Guaranteed

Institution
WGU D522 Python
Course
WGU D522 Python

Content preview

WGU D522 Python for IT Automation ACTUAL
OBJECTIVE ASSESSMENT PRACTICE 2026/2027 |
Verified Code-Centric & Scenario-Based Questions
and Answers | Grade A Target | Pass Guaranteed

SECTION 1: Python Foundations & Scripting Environment (Questions 1-10)

Q1: An IT automation script needs to handle a configuration value that may be missing. Which
code snippet properly implements safe retrieval with a default value?

A. value = config['timeout'] if config['timeout'] else 30 B. value = config.get('timeout', 30)
[CORRECT] C. value = config['timeout'] or 30 D. value = config.timeout || 30

Correct Answer: B

Rationale: The dict.get(key, default) method safely retrieves values without raising KeyError if
the key is absent. Option A fails with KeyError if 'timeout' doesn't exist. Option C also raises
KeyError before the or evaluation. Option D uses JavaScript syntax (||) and dot notation invalid
for Python dictionaries. This pattern is essential for robust configuration management in IT
automation.



Q2: [CODE ANALYSIS] What is the output of the following script?

Python

Copy

import sys



def main():

if len(sys.argv) != 3:

print("Usage: script.py <source> <destination>")

sys.exit(1)

, print(f"Copying {sys.argv[1]} to {sys.argv[2]}")



if __name__ == "__main__":

main()

Executed as: python script.py file1.txt

A. Copying file1.txt to B. Usage: script.py <source> <destination> [CORRECT] C. Copying file1.txt
to file1.txt D. No output; script hangs

Correct Answer: B

Rationale: The script validates argument count (len(sys.argv) includes script name, so 3
elements = 2 arguments). With only one argument provided, len(sys.argv) == 2, triggering the
usage message and sys.exit(1). This defensive pattern prevents undefined behavior and provides
clear user feedback—critical for IT automation tools used by operations teams.



Q3: Which shebang line should be used for a Python 3 automation script intended to run on
diverse Linux distributions?

A. #!/usr/bin/python B. #!/usr/bin/env python3 [CORRECT] C. #!/bin/python3 D. #!python3

Correct Answer: B

Rationale: #!/usr/bin/env python3 uses the environment's PATH to locate python3, ensuring
portability across systems where Python may be installed in /usr/bin, /usr/local/bin, or other
locations. Option A may invoke Python 2. Options C and D use non-standard or incomplete
paths. Portability is essential for deployment across heterogeneous infrastructure.



Q4: [MULTIPLE RESPONSE] Which practices improve error handling in IT automation scripts?
(Select all that apply.)

A. Using bare except: clauses to catch all errors B. Catching specific exceptions like
FileNotFoundError and PermissionError [CORRECT] C. Logging full stack traces for debugging
[CORRECT] D. Silently ignoring errors to ensure script completion E. Using finally blocks to
release resources [CORRECT]

Correct Answers: B, C, E

, Rationale: Specific exception handling (B) enables targeted responses (retry vs. abort). Logging
traces (C) aids post-incident analysis. finally blocks (E) ensure cleanup (file handles, network
connections). Bare except: (A) masks KeyboardInterrupt and SystemExit, preventing clean
shutdown. Silent error suppression (D) creates false positives and operational blind spots.



Q5: A script processes server hostnames. Which data structure provides O(1) membership
testing for deduplication?

A. hostnames = [] (list) B. hostnames = () (tuple) C. hostnames = set() [CORRECT] D. hostnames =
"" (string)

Correct Answer: C

Rationale: Sets implement hash tables, providing O(1) average-case lookup versus O(n) for
lists/tuples. For deduplicating thousands of server hostnames, set() dramatically improves
performance. Example: seen = set(); for h in hosts: if h not in seen: process(h); seen.add(h).



Q6: [CODE COMPLETION] Complete the function to safely parse an integer from environment
variable MAX_RETRIES, defaulting to 3:

Python

Copy

import os



def get_max_retries():

______

A. return int(os.getenv('MAX_RETRIES', 3)) B. return int(os.environ.get('MAX_RETRIES', 3))
[CORRECT] C. return int(os.environ['MAX_RETRIES']) or 3 D. return os.getenv('MAX_RETRIES', 3)

Correct Answer: B

Rationale: os.environ.get() safely retrieves with default. Option A uses os.getenv() (also valid
but less explicit). Option C raises KeyError if missing and int() fails on None. Option D returns
string 3, not integer. Explicit int() conversion ensures type correctness for subsequent numeric
comparisons.

Written for

Institution
WGU D522 Python
Course
WGU D522 Python

Document information

Uploaded on
February 7, 2026
Number of pages
30
Written in
2025/2026
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

$15.99
Get access to the full document:

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

Get to know the seller
Seller avatar
EMPRESS254
1.0
(1)

Get to know the seller

Seller avatar
EMPRESS254 Chamberlain College Of Nursing
View profile
Follow You need to be logged in order to follow users or courses
Sold
6
Member since
6 months
Number of followers
0
Documents
646
Last sold
21 hours ago
Empress

One stop shop for all all study materials, Study guides,Exams and all assignments and homeworks.

1.0

1 reviews

5
0
4
0
3
0
2
0
1
1

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