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-15
Section 2 Data Structures and Operations Q16-30
Section 3 Control Flow and Functions Q31-45
Section 4 File Handling and Exception Management Q46-60
Section 5 Automation Scripts and Libraries Q61-75
Instructions: Select the single best answer for each question. This exam is designed for WGU D522 Python for IT Automation certification
preparation. Passing score: 80% (60 questions correct).
WGU D522 Python for IT Automation -- 2026/2027 | Passing Score: 80% | Page 1 of 37
, SECTION 1 | Python Fundamentals and Syntax | Q1-Q15 | WGU D522 Python for IT Automation 2026/2027
Q1 Question 1 of 75
Q1. A junior developer is writing a Python script and needs to store a value that will not
change during execution, such as the maximum number of login attempts allowed. The
developer writes attempt_count = 5 at the top of the module. In Python, what is the
conventional way to indicate this value should not be reassigned?
A. Declare it as ATTEMPT_COUNT = 5 using all uppercase letters to signal it is a constant
B. Use the const keyword before the variable name like const attempt_count = 5
C. Write the value inside a frozen dictionary and reference it by key
D. Assign it inside a function decorated with @immutable
Correct Answer: A
Rationale:
Python has no const keyword; the convention of using ALL_CAPS signals intent to other developers that the value
should not be changed. Option B describes a language feature that does not exist in Python, and options C and D are
fabricated constructs.
Q2 Question 2 of 75
Q2. A data analyst runs a Python script and encounters a NameError on a variable that was
defined inside an if block. The variable was only assigned when the condition evaluated to
True. What is the most likely cause of this error?
A. Variables assigned inside an if block are scoped to that block and do not exist outside it in
Python
B. The variable name contained a hyphen which is not allowed in Python identifiers
C. Python requires all variables to be declared at the top of the file before any conditional logic
D. The if block created a new namespace that overrides the global namespace automatically
Correct Answer: A
Rationale:
In Python, variables assigned inside conditional blocks are function-scoped, not block-scoped. If the condition is False,
the variable is never created, causing a NameError when referenced later. Option B is incorrect because hyphens are
not allowed in identifiers but that is a different issue.
WGU D522 Python for IT Automation -- 2026/2027 | Passing Score: 80% | Page 2 of 37
,Q3 Question 3 of 75
Q3. An IT specialist needs to convert a user-entered string representing a port number into an
integer for a network configuration script. The user might enter non-numeric text accidentally.
What is the best approach to safely perform this conversion?
A. Wrap the int() conversion in a try/except block to catch ValueError if the string is not numeric
B. Use the str.isnumeric() method first and then call int() without any exception handling
C. Call int() directly and rely on the default Python error message to inform the user
D. Use float() instead of int() since it accepts a wider range of inputs
Correct Answer: B
Rationale:
While checking isnumeric() first seems reasonable, it does not handle edge cases like negative signs or whitespace.
Using try/except with int() is the Pythonic approach that handles all invalid conversions cleanly. Option C is a poor
approach, and option D would not produce the correct integer type.
Q4 Question 4 of 75
Q4. A developer writes a script that uses the expression 17 // 5 and expects the result to be
3.4. However, the output is 3. What does the // operator do in Python?
A. It performs floor division, returning the largest integer less than or equal to the exact quotient
B. It performs integer division only when both operands are integers, otherwise it returns a float
C. It rounds the result of normal division to the nearest integer using standard rounding rules
D. It performs modulo division and returns the remainder of the operation
Correct Answer: B
Rationale:
The // operator performs floor division, which always rounds down to the nearest integer. This is different from
truncation toward zero; for negative results, floor division yields a more negative number. Option D confuses // with the
modulo operator %.
WGU D522 Python for IT Automation -- 2026/2027 | Passing Score: 80% | Page 3 of 37
, Q5 Question 5 of 75
Q5. A systems engineer is writing a Python script that concatenates a string and an integer
value in a print statement: print('Server count: ' + 5). This raises a TypeError. What is the
correct way to fix this?
A. Convert the integer to a string using str() before concatenation: print('Server count: ' + str(5))
B. Use the plus operator with a type hint to tell Python to auto-convert: print('Server count: ' + int(5))
C. Declare the integer as a string from the beginning by wrapping it in single quotes inside the expression
D. Use the concat() built-in function which handles mixed types automatically
Correct Answer: A
Rationale:
Python does not allow implicit concatenation between strings and integers. The str() function explicitly converts the
integer to its string representation. Option B uses int() which would cause the same error, and options C and D
reference nonexistent functions.
Q6 Question 6 of 75
Q6. A programmer is debugging a script and discovers that the expression True + True
evaluates to 2 in Python. Which Python feature explains this behavior?
A. The bool type is a subclass of int where True equals 1 and False equals 0
B. Python automatically casts boolean values to integers whenever the plus operator is used
C. The plus operator has a special overload for boolean operands that returns their sum as an integer
D. True is stored internally as the integer 2 in Python and False as 1
Correct Answer: A
Rationale:
In Python, the bool class inherits from int, making True equivalent to 1 and False equivalent to 0. This design allows
boolean values to participate in arithmetic operations naturally. Options B and C describe mechanisms that do not exist
in Python.
WGU D522 Python for IT Automation -- 2026/2027 | Passing Score: 80% | Page 4 of 37