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
72
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 server hostnames that follow the pattern web-
01.prod.company.com. Which Python data structure is most appropriate for storing these
hostnames when the primary operations will be checking for membership (is this server in the
pool?) and ensuring no duplicates exist?

A. hostnames = ["web-01.prod.company.com", "web-02.prod.company.com"]
B. hostnames = ("web-01.prod.company.com", "web-02.prod.company.com")
C. hostnames = {"web-01.prod.company.com", "web-02.prod.company.com"} [CORRECT]
D. hostnames = "web-01.prod.company.com,web-02.prod.company.com"

Correct Answer: C

Rationale: A set (C) is the optimal choice for membership testing and deduplication. Sets
provide O(1) average-case lookup time for membership tests (in operator) versus O(n) for lists
and tuples. Sets inherently prevent duplicates, which is critical for server pools.

• Option A (list) allows duplicates and has slower membership testing.

• Option B (tuple) is immutable and also has O(n) membership testing.

• Option D (string) would require parsing and cannot represent multiple distinct
hostnames as separate elements without additional processing.

Pythonic best practice: Use sets when uniqueness and membership testing are primary
concerns, as in load balancer pools, firewall rule sets, or inventory management.



Q2: A system administrator writes the following script to check disk usage. What will be the
output?

,Python

Copy

#!/usr/bin/env python3

import sys



def check_disk(usage):

if usage > 90:

return "CRITICAL"

elif usage > 75:

return "WARNING"

return "OK"



try:

disk_usage = int(sys.argv[1])

status = check_disk(disk_usage)

print(f"Disk status: {status}")

except (IndexError, ValueError):

print("Usage: script.py <disk_usage_percent>")

sys.exit(1)

When executed as python3 script.py 85, what is printed?

A. Disk status: CRITICAL
B. Disk status: WARNING [CORRECT]
C. Disk status: OK
D. Usage: script.py <disk_usage_percent>

Correct Answer: B

Rationale: The value 85 is passed as a command-line argument, converted to integer 85. In
check_disk():

, • 85 > 90 is False, so not CRITICAL

• 85 > 75 is True, so returns "WARNING"

The elif condition is satisfied first, and the function returns immediately. The try/except block
handles the case where no argument is provided (IndexError) or a non-integer is provided
(ValueError).

• Option A would require > 90.

• Option C would require ≤ 75.

• Option D would trigger if no argument or non-integer was provided.

Best practice: Using sys.exit(1) indicates error status to calling processes/shell scripts, enabling
proper automation workflow handling.



Q3: [Multiple Response] Which of the following are valid ways to create a virtual environment
for Python 3.9+ and activate it on a Linux system? (Select all that apply.)

A. python3 -m venv /opt/automation/venv then source /opt/automation/venv/bin/activate
[CORRECT]
B. virtualenv /opt/automation/venv then source /opt/automation/venv/bin/activate [CORRECT]
C. python3 -m virtualenv /opt/automation/venv then . /opt/automation/venv/bin/activate
[CORRECT]
D. venv /opt/automation/venv then source /opt/automation/venv/Scripts/activate

Correct Answers: A, B, C

Rationale:

• A: The standard library venv module is the modern, recommended approach (PEP 405).
Activation uses source (or .) on the activate script in bin/ (Linux/macOS).

• B: The third-party virtualenv package remains valid and widely used, especially for older
Python versions or advanced features.

• C: Running virtualenv as a module via -m is valid syntax and equivalent to standalone
virtualenv command.

D is incorrect because:

• venv is not a standalone command; it must be called as python3 -m venv

• Scripts/activate is the Windows path; Linux uses bin/activate

, Operational note: Virtual environments isolate dependencies, preventing conflicts between
system Python packages and automation script requirements. Always document
requirements.txt and venv creation in deployment playbooks.



Q4: A log processing script uses the following pattern. What potential issue exists?

Python

Copy

def process_logs(log_files):

results = []

for file in log_files:

f = open(file, 'r')

data = f.read()

results.append(parse_log(data))

f.close()

return results

A. The script will fail if log_files contains non-existent files
B. File handles may not be closed if parse_log() raises an exception [CORRECT]
C. The results list will contain duplicate entries
D. Reading entire files into memory is inefficient for large logs

Correct Answer: B

Rationale: While D is technically true (streaming/lazy reading is better for large files), B
represents a critical resource leak bug. If parse_log(data) raises an exception, f.close() never
executes, leaving file descriptors open. On long-running automation jobs processing thousands
of logs, this causes "too many open files" errors (OSError: [Errno 24]).

The Pythonic solution uses context managers:

Python

Copy

with open(file, 'r') as f:

Written for

Institution
WGU D522
Course
WGU D522

Document information

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

Subjects

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