WGU D522 Objective Assessment
(New 2026/2027 Update) Python for IT Automation
2026/2027 ACTUAL EXAM TEST BANK
WITH REAL EXAM QUESTIONS AND
100% CORRECT VERIFIED ANSWERS (GUARANTEED PASS!!)
Aligned to WGU Content Outline • IT Automation Level
A+ 5 100%
QUESTIONS SECTIONS RATIONALES
VERIFIED COMPLETE INCLUDED
CATEGORIES
■ SECTION 1 — Python Fundamentals & Syntax
■ SECTION 2 — Data Structures & File Handling
■ SECTION 3 — Modules, Packages, Errors & Debugging
■ SECTION 4 — Automation Scripting (OS, Subprocess, Regex, Networking)
■ SECTION 5 — Practical IT Automation, Security & Best Practices
STUVIAACTUALEXAM
Aligned to WGU D522 Python for IT Automation • 2026/2027
, SECTION 1: PYTHON FUNDAMENTALS & SYNTAX
Q1. An IT automation script needs to store a server hostname that will never change during execution. A junior administrator wrote: server
= 'web01.example.com'. A peer review asks whether a different construct would better communicate intent. Which approach most clearly
signals a constant value in Python while remaining conventional for scripts?
A. Use a tuple containing the string and never index it
B. Wrap the string in a frozenset before assignment
C. Name the variable in uppercase (SERVER = 'web01.example.com') to signal a constant by convention
D. Declare the variable with the const keyword before the name
Correct Answer: C
Rationale: Python has no const keyword. The community convention is to use UPPER_SNAKE_CASE names for values that should not be reassigned,
signaling intent to other maintainers.
Q2. A script processes log lines and must decide whether a line contains the substring 'ERROR'. The developer writes: if 'ERROR' in line:
... What is the primary advantage of using the in operator with a string in this context?
A. It always performs a case-insensitive search without extra flags
B. It converts the line to a list of characters before searching
C. It raises an exception if the substring is missing, forcing explicit handling
D. It returns True if the substring exists anywhere in the string, providing a clear and efficient membership test
Correct Answer: D
Rationale: The in operator for strings performs a substring membership test and returns a Boolean. It is the idiomatic, readable way to check for presence of
text in a line.
Q3. An automation script must iterate over a list of hostnames and print each one with its 1-based index for an audit report. The developer
wants both the index and the value. Which construct is the most Pythonic solution?
A. Manual counter variable incremented inside a plain for loop only
B. for i, host in enumerate(hosts, start=1): print(i, host)
C. Using range(len(hosts)) and indexing without enumerate
D. Converting the list to a dictionary of indexes before looping
Correct Answer: B
Rationale: enumerate pairs each item with an index. The start parameter sets the first index to 1, which matches human-readable numbering in reports.
Q4. A function is defined as def connect(host, port=22, timeout=30):. A caller invokes connect('db01', timeout=10). Which values do port
and timeout receive?
A. port=22 (default) and timeout=10 (explicit keyword argument)
B. port=10 and timeout=22 because positional order is forced
C. Both remain unset and raise TypeError
D. port=10 and timeout=30
Correct Answer: A
Rationale: Keyword arguments can be supplied out of order. host is positional, timeout is overridden by name, and port keeps its default of 22.
Q5. A script needs to build a multi-line configuration string that includes variable values for hostname and port. The developer wants
readable interpolation. Which approach is preferred in modern Python for clarity and safety?
A. Concatenating with + and str() calls only
B. Relying solely on the % operator with a single tuple
C. Joining a list of characters one by one
D. Using an f-string such as config = f'host={hostname}\nport={port}'
Correct Answer: D
Rationale: f-strings provide concise, readable interpolation of expressions inside curly braces and are the preferred modern approach for this kind of string
building.
Q6. An automation task must run a block of code at least once and then repeat while a connection flag remains True. Which loop structure
best expresses 'execute once, then continue while condition holds'?
A. A for loop over an infinite range only
B. A while True loop with a conditional break after the first iteration, or an explicit do-while simulation using while with a trailing check
C. A plain for loop over a fixed list of length one
D. Using map() with a lambda that never terminates
Correct Answer: B
Rationale: Python lacks a built-in do-while. The standard pattern is while True: ...; if not condition: break, which guarantees one execution and then continues
while the condition remains true.
Q7. A developer writes: result = . In Python 3, what is the type and approximate value of result?
STUVIAACTUALEXAM | Page 2 of 13