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



Q1: An IT automation script needs to process a list of server hostnames and ensure no
duplicates exist while maintaining the original order of first appearance. Which Python code
segment accomplishes this most efficiently?

A. unique_servers = list(set(server_list)) B. unique_servers = sorted(set(server_list),
key=server_list.index) C. seen = set(); unique_servers = [x for x in server_list if not (x in seen or
seen.add(x))] [CORRECT] D. unique_servers = []; [unique_servers.append(x) for x in server_list if
x not in unique_servers]

Correct Answer: C

Rationale: Option C uses a set for O(1) membership testing while preserving order through a list
comprehension with side effect. The seen set tracks encountered items; the or short-circuit
ensures add() only executes if x not in seen is True. This achieves O(n) time complexity. Option A
loses original order (sets are unordered). Option B is O(n²) due to index() calls. Option D is O(n²)
due to linear not in searches on a growing list. For IT automation processing large infrastructure
inventories, Option C provides optimal performance. [CORRECT: C]



Q2: A system administrator is writing a script to handle potential file access errors. Which
exception handling structure follows Python best practices for catching specific errors while
avoiding bare except clauses?

A.

Python

Copy

try:

with open('/etc/passwd', 'r') as f:

, data = f.read()

except:

print("Error occurred")

B.

Python

Copy

try:

with open('/etc/passwd', 'r') as f:

data = f.read()

except FileNotFoundError as e:

logger.error(f"Password file missing: {e}")

except PermissionError as e:

logger.error(f"Insufficient permissions: {e}")

except Exception as e:

logger.critical(f"Unexpected error: {e}")

raise

``` [CORRECT]



C.

```python

try:

f = open('/etc/passwd', 'r')

data = f.read()

except (FileNotFoundError, PermissionError, OSError):

print("File access failed")

finally:

, f.close()

D.

Python

Copy

try:

data = open('/etc/passwd', 'r').read()

except Exception:

pass

Correct Answer: B

Rationale: Option B demonstrates proper exception hierarchy: specific exceptions
(FileNotFoundError, PermissionError) are caught first for targeted handling, followed by a
general Exception handler that logs and re-raises unexpected errors. This follows PEP 8 and the
Zen of Python ("Errors should never pass silently"). The with statement ensures proper resource
cleanup. Option A uses a bare except, catching KeyboardInterrupt and SystemExit
inappropriately. Option C risks UnboundLocalError if open() fails before f is assigned. Option D
silently suppresses all errors, masking critical failures in automation scripts. [CORRECT: B]



Q3: [Code Analysis] What is the output of the following script when executed on a Linux
system?

Python

Copy

#!/usr/bin/env python3

import sys



def main():

if len(sys.argv) < 2:

print("Usage: script.py <hostname>", file=sys.stderr)

sys.exit(1)

, hostname = sys.argv[1]

domain_parts = hostname.split('.')



if len(domain_parts) >= 2:

print(f"Domain: {'.'.join(domain_parts[-2:])}")

else:

print("Invalid FQDN")



if __name__ == "__main__":

main()

Executed as: python3 script.py web01.prod.example.com

A. Domain: web01.prod B. Domain: example.com [CORRECT] C. Domain: prod.example.com D.
Usage: script.py <hostname>

Correct Answer: B

Rationale: The script extracts the last two domain components. hostname.split('.') produces
['web01', 'prod', 'example', 'com']. The slice [-2:] selects ['example', 'com'], which join()
combines as "example.com". This is a common pattern in IT automation for extracting domain
information from FQDNs. Option A incorrectly takes the first two elements. Option C takes
elements 1-3 (index 1 onward). Option D would only occur with no command-line arguments
provided. [CORRECT: B]



Q4: Which shebang line should be used for a Python 3 automation script intended to run across
heterogeneous Unix-like environments (Linux, macOS, BSD) where Python may be installed in
various locations?

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

Correct Answer: C

Rationale: #!/usr/bin/env python3 uses the env command to locate python3 in the user's
$PATH, ensuring portability across systems where Python may be in /usr/bin, /usr/local/bin,

Written for

Institution
WGU D522
Course
WGU D522

Document information

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

Subjects

$16.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