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 36
, SECTION 1 | Python Fundamentals and Syntax | Q1-Q15 | WGU D522 Python for IT Automation 2026/2027
Q1 Question 1 of 75
A developer writes a Python script that needs to prompt the user for an integer value and store it for later
calculation. The script must handle the input conversion correctly without raising a TypeError. Which
approach correctly reads and stores the integer?
A. Using input('Enter a number: ') which automatically returns an integer type
B. Using str(input('Enter a number: ')) and relying on implicit conversion during arithmetic
C. Using int(input('Enter a number: ')) to read and convert the input in one step
D. Using float(input('Enter a number: ')) and truncating the decimal with modulo
Correct Answer: C
Rationale:
The input() function always returns a string in Python 3, so int() must wrap it to convert to an integer. Using
input() alone stores a string, str() wraps an already-string value, and float() returns a float, not an int.
Q2 Question 2 of 75
A systems administrator is troubleshooting a script where a variable named count has been assigned inside
a function but the outer scope reports it as undefined. The script uses no global declarations. Which Python
scope rule explains this behavior?
A. Variables in Python have function scope by default and are visible everywhere in the module
B. Python uses block-level scoping so the variable is visible only within the if-block
C. Inner function variables are automatically promoted to module scope after the function returns
D. LEGB rule - variables assigned inside a function are local to that function unless declared global
Correct Answer: D
Rationale:
Python follows LEGB (Local, Enclosing, Global, Built-in) resolution. A variable assigned inside a function is local
to that function unless explicitly declared global. Unlike some languages, Python does not use block-level or
function-hoisting scope.
WGU D522 Python for IT Automation - 2026/2027 | Passing Score: 80% | Page 2 of 36
, SECTION 1 | Python Fundamentals and Syntax | Q1-Q15 | WGU D522 Python for IT Automation 2026/2027
Q3 Question 3 of 75
A junior developer creates a variable named 2nd_value in a Python script and receives a SyntaxError. The
developer reviews PEP 8 naming conventions to understand valid identifier rules. Which statement correctly
describes Python identifier naming?
A. Identifiers can start with a digit as long as the rest contains only letters
B. Identifiers must start with a letter or underscore and cannot begin with a digit
C. Identifiers are case-insensitive so 2nd_value is the same as Second_Value
D. Identifiers can contain any character if enclosed in backticks
Correct Answer: B
Rationale:
Python identifiers must begin with a letter (a-z, A-Z) or underscore and can be followed by letters, digits, or
underscores. Starting with a digit like 2nd_value causes a SyntaxError. Python identifiers are case-sensitive and
backticks are not used for identifiers.
Q4 Question 4 of 75
An IT analyst needs to concatenate a string message with an integer error_code in a log statement. The
analyst writes 'Error: ' + error_code and gets a TypeError. Which is the correct way to build this string?
A. Using 'Error: ' + int(error_code) to force both operands to integers before the plus sign acts
B. Using 'Error: ' + str(error_code) to explicitly convert the integer before concatenation
C. Using 'Error: ' . error_code because the dot operator auto-converts types in Python
D. Using 'Error: ' + error_code inside a try block so the exception handler performs the conversion
Correct Answer: B
Rationale:
Python does not allow implicit concatenation between str and int types. The + operator requires both operands to
be the same type. str() converts the integer to its string representation so concatenation succeeds. The dot
operator and try-except do not perform automatic type conversion.
WGU D522 Python for IT Automation - 2026/2027 | Passing Score: 80% | Page 3 of 36
, SECTION 1 | Python Fundamentals and Syntax | Q1-Q15 | WGU D522 Python for IT Automation 2026/2027
Q5 Question 5 of 75
A developer wants to store configuration values that should never change during program execution, such
as MAX_RETRIES = 5 and API_URL. Which Python convention signals that a variable is intended to be a
constant?
A. Using the const keyword before the variable name as in other programming languages
B. Declaring the variable inside a __constants__ module which Python treats as read-only
C. Prefixing the variable with two underscores so Python enforces immutability via name mangling
D. Naming the variable in ALL_CAPS with underscores to indicate it should be treated as a constant
Correct Answer: D
Rationale:
Python has no const keyword. The PEP 8 convention is to use ALL_CAPS_WITH_UNDERSCORES for
constants. This is a naming convention - Python does not enforce immutability, but it signals the programmer's
intent. Name mangling with double underscores is for class attribute privacy, not constants.
Q6 Question 6 of 75
A script contains the expression result = 17 // 5 and the developer expects the value 3.4, but the interpreter
returns 3. Which operation should the developer use instead to obtain the floating-point quotient?
A. Using the / operator as in which returns 3.4 in Python 3
B. Using the % operator as in 17 % 5 which returns the decimal remainder
C. Using the // operator with a float operand as in 17.0 // 5 which returns 3.4
D. Using the divmod() function which always returns a floating-point quotient
Correct Answer: A
Rationale:
The // operator is floor division and always truncates toward negative infinity, returning an integer result when
both operands are integers. The / operator performs true division and returns a float (3.4). The % operator
returns the modulo remainder, and divmod() returns a tuple of (quotient, remainder).
WGU D522 Python for IT Automation - 2026/2027 | Passing Score: 80% | Page 4 of 36