WGU D522 Objective Assessment
(New 2026/2027 Update) Python for IT Automation
Official Exam
70 Questions Full Rationales Verified Answers
70 5 100%
QUESTIONS SECTIONS RATIONALES
Complete coverage Core exam domains Every answer explained
WHAT THIS COVERS
01 Python Fundamentals and Syntax
02 Data Structures and File Handling
03 Scripting for System Administration
04 Networking and API Automation
05 Error Handling and Best Practices
ABOUT THIS ASSESSMENT
Build mastery in Python for IT automation — from Python fundamentals and data structures to system administration scripting, networking and API
automation, and error handling best practices. This original study bank targets application and analysis skills for the WGU D522 Objective Assessment,
with full rationales for every answer. For review use only; not an institutional proctored assessment.
PASSING SCORE LEVEL FORMAT
75% Intermediate Application / Analysis
STUVIA ACTUAL EXAM Page 1
, SECTION 1: Python Fundamentals and Syntax
Q1. An IT automation script must calculate the remaining disk space percentage given total and used space in gigabytes. The
developer writes: remaining = (total - used) / total * 100. When total is 0 the script crashes. Which change correctly prevents
the crash while preserving the calculation for valid inputs?
A. Wrap the expression in a try block that returns 0 on ZeroDivisionError
B. Use remaining = (total - used) / total * 100 if total else 0
C. Replace the division with integer floor division //
D. Cast total to a string before dividing
Correct Answer: A
Rationale: A conditional expression (or guard) that returns 0 when total is falsy avoids ZeroDivisionError without altering the normal
arithmetic path. A bare try/except is less precise; floor division and string casting produce incorrect results.
Q2. A junior engineer needs to store a constant list of approved ports that must never be modified after definition. Which
Python construct best communicates and enforces this intent at the module level?
A. ports = [22, 80, 443] and rely on documentation only
B. PORTS = (22, 80, 443) using an uppercase name and a tuple
C. ports = {22, 80, 443} as a set
D. ports = list(range(22, 444))
Correct Answer: C
Rationale: Tuples are immutable and the conventional UPPER_CASE name signals a constant. Lists and sets remain mutable; a generated
range does not clearly express a fixed approved set.
Q3. While reviewing a script that parses log lines, a developer sees the statement: if status == "error" or "fail":. The condition
always evaluates to True. Why does this occur and what is the correct form?
A. Python treats the string "fail" as a non-empty truthy value; write if status in ("error", "fail")
B. The or operator has higher precedence than ==; add parentheses around the comparison
C. String comparison is case-sensitive; convert status to lower case first
D. The variable status is shadowed; rename it to line_status
Correct Answer: C
Rationale: In Boolean context a non-empty string is always True, so the expression becomes True regardless of status. Membership testing
against a tuple or set is the idiomatic fix.
Q4. A script must accept a command-line argument for the target hostname and provide a sensible default when the argument
is omitted. Which approach using the standard library is most appropriate?
A. sys.argv[1] without any length check
B. argparse.ArgumentParser with an optional argument that has a default value
C. input() inside a try/except block
D. os.environ.get("HOSTNAME") exclusively
Correct Answer: A
Rationale: argparse is the standard, robust way to declare optional arguments with defaults and automatic help text. Direct sys.argv indexing
is fragile; input() is interactive; environment variables alone do not handle CLI flags.
STUVIA ACTUAL EXAM · Page 2
, Q5. A developer needs to iterate over a list of server names and their corresponding IP addresses simultaneously. Both lists
are the same length. Which construct is the cleanest and most Pythonic?
A. for i in range(len(servers)): print(servers[i], ips[i])
B. for server, ip in zip(servers, ips):
C. for server in servers: for ip in ips:
D. list(map(lambda s, i: (s, i), servers, ips))
Correct Answer: D
Rationale: zip pairs corresponding elements cleanly and stops at the shorter sequence. Nested loops produce a Cartesian product;
range(len()) is less readable; map with lambda is unnecessarily complex for this case.
Q6. An automation module defines a function that should return the string "success" when a configuration change is applied
and "failed" otherwise. The author wrote: return "success" if applied else return "failed". What is the syntax problem and the
correct rewrite?
A. A ternary expression cannot contain a second return; write return "success" if applied else "failed"
B. The else clause must be indented on a new line
C. String literals require single quotes only
D. The function must be declared with async def
Correct Answer: D
Rationale: A conditional expression is itself an expression; it cannot embed a statement such as return. The correct form places the entire
ternary after a single return.
Q7. A script processes a large CSV of inventory items and must skip the header row. The developer opens the file with
csv.reader. Which technique correctly advances past the first row?
A. reader.next() in Python 3
B. next(reader) or next(reader, None)
C. reader.seek(1)
D. del reader[0]
Correct Answer: B
Rationale: In Python 3 the built-in next() advances an iterator. csv.reader objects do not support next() as a method, seek, or item deletion.
Q8. While writing a configuration parser the engineer needs to test whether a key exists in a dictionary and retrieve its value,
supplying a default of None when the key is absent. Which method is preferred for clarity and performance?
A. if key in d: value = d[key] else: value = None
B. value = d.get(key)
C. value = d[key] if key else None
D. value = d.pop(key, None)
Correct Answer: D
Rationale: dict.get(key) returns the value or None by default without raising KeyError and without mutating the dictionary. pop would remove
the key; the explicit if is more verbose.
STUVIA ACTUAL EXAM · Page 3