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
86
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
Course
WGU D522

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 (10 Questions)



Q1: A system administrator needs to create a Python script that processes server hostnames.
The script should accept a variable number of hostname arguments and validate that each
contains only alphanumeric characters and hyphens. Which function signature and validation
approach is most Pythonic?

A.

Python

Copy

def validate_hosts(host_list):

for host in host_list:

if not host.isalnum():

return False

return True

B.

Python

Copy

def validate_hosts(*hosts):

return all(h.replace('-', '').isalnum() for h in hosts) [CORRECT]

C.

Python

,Copy

def validate_hosts(hosts):

valid = True

for i in range(len(hosts)):

if not re.match(r'^[a-zA-Z0-9-]+$', hosts[i]):

valid = False

return valid

D.

Python

Copy

def validate_hosts(**hosts):

return [h for h in hosts.values() if h.isalnum()]

Correct Answer: B
Rationale: Option B demonstrates Pythonic practices: using *hosts for variadic arguments
(accepting any number of positional arguments), generator expression with all() for efficient
short-circuit evaluation, and str.replace() combined with isalnum() for validation. The all()
function stops at the first False, optimizing performance. Option A fails because isalnum()
rejects hyphens, which are valid in hostnames. Option C works but is verbose; the regex is
unnecessary when string methods suffice, and manual indexing with range(len()) is unPythonic.
Option D incorrectly uses **kwargs (for keyword arguments) and returns a list instead of a
boolean, while also failing to handle hyphens.



Q2: A DevOps engineer is writing a configuration parser. The code needs to handle missing
configuration keys gracefully. Which implementation best follows Python exception handling
best practices?

A.

Python

Copy

def get_config_value(config, key):

, try:

return config[key]

except:

return None

B.

Python

Copy

def get_config_value(config, key):

if key in config:

return config[key]

else:

raise KeyError(f"Key {key} not found")

C.

Python

Copy

def get_config_value(config, key):

try:

return config[key]

except KeyError:

return config.get('default', None) [CORRECT]

except TypeError:

raise ValueError("Config must be a dictionary")

D.

Python

Copy

def get_config_value(config, key):

, return config[key] or None

Correct Answer: C
Rationale: Option C demonstrates proper exception handling: catching specific exceptions
(KeyError, TypeError) rather than bare except, providing fallback behavior for missing keys, and
raising descriptive errors for invalid input types. This follows EAFP (Easier to Ask Forgiveness
than Permission) and maintains clear error boundaries. Option A uses bare except which
catches KeyboardInterrupt and SystemExit, making the script unkillable—an anti-pattern.
Option B violates the principle of least surprise by raising an exception for a missing key when a
default return would be more useful; it also uses LBYL (Look Before You Leap) which is less
Pythonic than EAFP for this case. Option D doesn't handle the case where key doesn't exist
(raises KeyError) and misuses or logic.



Q3: An automation script needs to process a list of server dictionaries, extracting only servers in
the "production" environment with status "running". Which list comprehension is correct?

Given data:

Python

Copy

servers = [

{'name': 'web01', 'env': 'production', 'status': 'running'},

{'name': 'web02', 'env': 'staging', 'status': 'running'},

{'name': 'db01', 'env': 'production', 'status': 'stopped'}

]

A.

Python

Copy

prod_running = [s for s in servers if s['env'] == 'production'

and s.status == 'running']

B.

Python

Written for

Institution
WGU D522
Course
WGU D522

Document information

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

Subjects

$15.49
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