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 certification preparation. Passing score: 80% (60 questions correct).
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 developer is writing a Python script that needs to assign the value 42 to a variable named
count and then print it. The script must follow PEP 8 naming conventions. A junior colleague
suggests using Count = 42 as the assignment. What should the developer do instead?
A. Use count = 42 because PEP 8 recommends lowercase with underscores for variable names
B. Use Count = 42 because it follows CamelCase convention for all variables
C. Use COUNT = 42 because uppercase is preferred for integer variables
D. Use _count = 42 because leading underscores improve readability
Correct Answer: A
Rationale:
PEP 8 specifies that variable names should use lowercase letters with words separated by underscores
(snake_case). CamelCase (Count) is reserved for class names, and all-uppercase names are reserved
for constants. Using a leading underscore indicates a private variable, which is not appropriate for a
general-purpose counter.
Q2 Question 2 of 75
A system administrator is reviewing a Python 3 script and encounters the line result = . The
administrator expects an integer result of 3 but gets 3.3333 instead. Which operation should be
used to obtain the integer quotient?
A. result = 10 % 3
B. result = 10 // 3
C. result =
D. result = int(.0)
Correct Answer: B
Rationale:
The floor division operator // returns the integer quotient of a division, discarding the remainder. The
single slash / performs true division returning a float in Python 3. While int(.0) also yields 3, it is
unnecessarily complex and uses floating-point division before truncation. The modulo operator %
returns the remainder, not the quotient.
WGU D522 Python for IT Automation - 2026/2027 | Passing Score: 80% | Page 2 of 39
,Q3 Question 3 of 75
A programmer needs to concatenate a string variable name with the literal string '_report' to
create a filename. The variable name holds the value 'quarterly'. Which approach correctly
produces 'quarterly_report'?
A. filename = name.append('_report')
B. filename = name + _report
C. filename = name + '_report'
D. filename = name.concat('_report')
Correct Answer: C
Rationale:
The + operator concatenates strings in Python. Without quotes, _report would be treated as a variable
name, not a string literal. The .append() method is for lists, not strings, and .concat() is not a built-in
string method in Python. String concatenation with + is the standard approach for joining strings.
Q4 Question 4 of 75
An IT analyst is converting user input to an integer but the program crashes when the user types
'twenty' instead of '20'. The analyst needs a Python expression that safely handles this
conversion. Which built-in method checks whether a string can be converted to an integer before
attempting the conversion?
A. The type() function comparing the input to int
B. The isnumeric() function directly converting the string
C. The eval() function wrapping the input string
D. The str.isdigit() method on the input string before calling int()
Correct Answer: D
Rationale:
The str.isdigit() method returns True only if all characters in the string are digits, making it a reliable
pre-check before calling int(). The type() function checks the type of an existing object, not whether a
string is convertible. There is no standalone isnumeric() function in Python (it is a string method with
broader Unicode digit coverage). Using eval() is dangerous because it executes arbitrary code, creating
a security vulnerability.
WGU D522 Python for IT Automation - 2026/2027 | Passing Score: 80% | Page 3 of 39
, Q5 Question 5 of 75
A Python developer needs to store configuration values that should never change during program
execution, such as MAX_RETRIES = 5 and API_ENDPOINT = 'https://api.example.com'.
According to PEP 8, how should these names be formatted?
A. Use all uppercase letters with underscores: MAX_RETRIES, API_ENDPOINT
B. Use CamelCase: MaxRetries, ApiEndpoint
C. Use lowercase with underscores: max_retries, api_endpoint
D. Use a single leading underscore: _MAX_RETRIES, _API_ENDPOINT
Correct Answer: A
Rationale:
PEP 8 dictates that constants should be named using all uppercase letters with words separated by
underscores. CamelCase is for class names. Lowercase with underscores is for regular variables and
function names. A single leading underscore indicates a private attribute, which is a separate naming
convention unrelated to constants.
Q6 Question 6 of 75
A junior developer writes x = 5 and then y = x, expecting y to remain 5 even after x is later
changed to 10. When x changes to 10, y remains 5. What concept explains this behavior in
Python?
A. Python creates a deep copy of the value when assigning y = x
B. Variables in Python are references to objects; reassigning x creates a new object, leaving y
referencing the original integer 5
C. Integer variables in Python are statically typed and cannot change
D. The assignment y = x creates a linked reference that updates in both directions
Correct Answer: B
Rationale:
In Python, variables are labels (references) pointing to objects in memory. When x = 5 is executed, x
points to the integer object 5. The statement y = x makes y point to the same object 5. When x = 10 is
later executed, x is reassigned to point to a new integer object 10, but y still points to the original object
5. This is not a deep copy mechanism; integers are immutable, so no copying is needed.
WGU D522 Python for IT Automation - 2026/2027 | Passing Score: 80% | Page 4 of 39