WESTERN GOVERNORS UNIVERSITY
WGU D522 Objective Assessment
(New 2026/2027 Update) Python for IT Automation
Qs & As | Grade A | 100% Correct (Verified Answers)
2026/2027 Edition - Official Exam 2026/2027
75 80% N/A
QUESTIONS PASSING SCORE RECERTIFICATION
TABLE OF CONTENTS
Section 1 Python Fundamentals and Syntax Q1-Q15
Section 2 Data Structures and Operations Q16-Q30
Section 3 Control Flow and Functions Q31-Q45
Section 4 File Handling and Exception Management Q46-Q60
Section 5 Automation Scripts and Libraries Q61-Q75
Instructions: Select the single best answer for each question. This exam is designed for WGU D522 Python for IT Automation
WGU D522 Python for IT Automation - 2026/2027 | Passing Score: 80% | Page 1 of 39
, SECTION 1 | Python Fundamentals and Syntax | Q1-Q15 | WGU D522 Python for IT Automation 2026/2027
Q1 Question 1 of 75
A systems administrator is writing a Python script to document server configurations and
needs to assign a server's IP address to a variable. The variable must follow Python naming
conventions and hold the string value '10.0.0.1'. The correct assignment statement is which of
the following?
A. server_ip = 10.0.0.1
B. server-ip = '10.0.0.1'
C. server_ip = '10.0.0.1'
D. Server IP = '10.0.0.1'
Correct Answer: C
Rationale:
The variable name server_ip follows Python naming rules (letters, underscores, digits, no hyphens or
spaces) and the IP address must be a string in quotes. Option A omits quotes, making Python interpret it as
numeric syntax causing a syntax error. Option C uses a hyphen which is not allowed in variable names.
Option D contains a space which is invalid in Python identifiers.
Q2 Question 2 of 75
A developer is troubleshooting a Python script that concatenates a string with an integer to
build a status message. The script raises a TypeError when executed. The line causing the
error is: message = 'Server count: ' + 42. The correct fix to produce the output 'Server count:
42' is which of the following?
A. message = 'Server count: ' + int(42)
B. message = str('Server count: ') + 42
C. message = 'Server count: ' . str(42)
D. message = 'Server count: ' + str(42)
Correct Answer: D
Rationale:
Python cannot concatenate a string with an integer directly; the integer must be converted to a string using
str(). Option A wraps 42 in int() which is redundant and does not solve the type mismatch. Option C uses dot
notation which is invalid for string concatenation. Option D converts the string portion but leaves 42 as an
integer, still causing the TypeError.
WGU D522 Python for IT Automation - 2026/2027 | Passing Score: 80% | Page 2 of 39
, SECTION 1 | Python Fundamentals and Syntax | Q1-Q15 | WGU D522 Python for IT Automation 2026/2027
Q3 Question 3 of 75
A network engineer is documenting Python data types in an automation playbook. She needs
to store a list of switch port numbers that should not change during execution. The data type
that enforces immutability for this sequence of values is which of the following?
A. list
B. dict
C. tuple
D. set
Correct Answer: C
Rationale:
A tuple is an immutable sequence type in Python, meaning its elements cannot be modified after creation.
This makes it ideal for storing fixed collections like port numbers that should remain constant. A list is
mutable and allows modifications. A dict stores key-value pairs, not just a sequence. A set is mutable and
does not preserve order or allow duplicates.
Q4 Question 4 of 75
An IT analyst writes a Python expression to calculate available disk space after allocating
25% to a new partition. If total_gb = 500, the expression that correctly computes the remaining
space as 375.0 is which of the following?
A. remaining = total_gb - (total_gb / 100 * 25)
B. remaining = total_gb - total_gb / 100 * 25
C. remaining = total_gb - (total_gb % 25)
D. remaining = total_gb // 4 * 3
Correct Answer: A
Rationale:
Option A uses parentheses to enforce correct order of operations: divide total by 100 to get 1%, multiply by
25 to get 25%, then subtract from total, yielding 375.0. Option B lacks parentheses around the percentage
calculation but still works due to Python's left-to-right evaluation of same-precedence operators. Option C
uses the modulo operator which calculates remainder, not percentage. Option D uses integer division which
gives 375 (integer) rather than 375.0 and is less readable for percentage calculations.
WGU D522 Python for IT Automation - 2026/2027 | Passing Score: 80% | Page 3 of 39
, SECTION 1 | Python Fundamentals and Syntax | Q1-Q15 | WGU D522 Python for IT Automation 2026/2027
Q5 Question 5 of 75
A DevOps engineer is creating a configuration dictionary and needs to check the data type of
a variable named config_value before processing it. The built-in Python function that returns
the type of an object is which of the following?
A. typeof(config_value)
B. datatype(config_value)
C. type(config_value)
D. get_type(config_value)
Correct Answer: C
Rationale:
The type() function is the built-in Python function that returns the type of an object. typeof() is used in
JavaScript, not Python. datatype() and get_type() are not built-in Python functions. Using type(config_value)
returns something like <class 'str'> which allows the engineer to verify the variable's type before processing.
Q6 Question 6 of 75
A junior developer receives an IndentationError when running a Python script that defines a
function. The script uses a mix of tabs and spaces for indentation. The Python style guideline
(PEP 8) recommendation for indentation is which of the following?
A. Use 2 spaces per indentation level for consistency with other languages
B. Use tabs exclusively because they are more portable across editors
C. Use 4 spaces per indentation level and avoid mixing tabs and spaces
D. Use 8 spaces per indentation level for maximum readability
Correct Answer: C
Rationale:
PEP 8 recommends using 4 spaces per indentation level and explicitly advises against mixing tabs and
spaces, which causes IndentationError. Two spaces are common in JavaScript but not Python. Tabs alone
are discouraged in PEP 8 in favor of spaces. Eight spaces is excessive and not the Python standard.
WGU D522 Python for IT Automation - 2026/2027 | Passing Score: 80% | Page 4 of 39