WGU D522 – PYTHON FOR IT AUTOMATION |
STUDY GUIDE | LATEST UPDATE 2026/2027 |
PRACTICE QUESTIONS AND ANSWERS |
EXAM REVIEW
Table of Contents
1. Python Fundamentals: Syntax, Variables, and Data Types
2. Operators and Control Flow
3. Data Structures: Lists, Tuples, Dictionaries, and Sets
4. Functions and Modular Programming
5. File Handling and I/O Operations
6. Exception Handling and Debugging
7. Automation Techniques: Scripting and Scheduling
8. APIs and Data Serialization: JSON and REST
9. Regular Expressions and Text Processing
, WGU D522 | 2
Question 1: What does Python syntax refer to?
A) The runtime environment for executing Python code
B) The set of rules that dictate the combinations of symbols and keywords that form valid
Python programs
C) The process of converting Python code into machine language
D) The standard library of built-in modules included with Python
Correct Answer: B) The set of rules that dictate the combinations of symbols and
keywords that form valid Python programs
Python syntax encompasses the grammar rules that define how symbols, keywords, and
operators can be combined to create valid Python programs. Syntax rules govern everything
from variable naming conventions to statement structure, ensuring the interpreter can
correctly parse and execute the code.
Question 2: What is the primary purpose of indentation in Python?
A) To enhance visual appearance without affecting execution
B) To define blocks of code
C) To separate different modules
D) To indicate the end of a program
Correct Answer: B) To define blocks of code
Unlike many other programming languages that use braces {} to define code blocks, Python
uses indentation (spaces or tabs at the start of a line) to define blocks of code. Consistent
indentation is required for structures like if statements, loops, and function definitions.
Question 3: Which of the following is a valid variable name in Python?
A) 2ndPlace
B) total-score
, WGU D522 | 3
C) firstName
D) class
Correct Answer: C) firstName
Variable names in Python must start with a letter or underscore, cannot contain spaces or
hyphens, and cannot be reserved keywords. firstName follows these rules, while 2ndPlace
starts with a digit, total-score contains a hyphen, and class is a reserved keyword.
Question 4: What is the data type of the result when you calculate ((total_hours - downtime) /
total_hours) * 100 if total_hours is an integer and downtime is a float?
A) Integer (int)
B) Floating-point number (float)
C) String (str)
D) Boolean (bool)
Correct Answer: B) Floating-point number (float)
Even though total_hours is an integer, the division operation in Python 3 always produces a
float to maintain decimal precision. The subsequent multiplication keeps it as a float, which
is exactly what you need for precise percentage calculations.
Question 5: A junior developer asks why their boolean variable is_connected = "False"
evaluates to True in their conditional check. What is the root cause of this unexpected
behavior?
A) The variable name contains underscores which Python interprets as True
B) "False" as a string is truthy because it's a non-empty string
C) Boolean variables must be declared using the bool() constructor exclusively
D) Python treats all quoted text as logical True by default
Correct Answer: B) "False" as a string is truthy because it's a non-empty string
In Python, any non-empty string—including the text "False"—evaluates to True in a boolean
context. The quotes make it a string literal, not the boolean False value. The correct
assignment would be is_connected = False without any quotes.
, WGU D522 | 4
Question 6: You need to convert user input from a text file—stored as the string "4500"—to
an integer for memory allocation calculations. Which code accomplishes this conversion
correctly?
A) memory = "4500".toInteger()
B) memory = integer("4500")
C) memory = int("4500")
D) memory = str(4500)
Correct Answer: C) memory = int("4500")
Python's built-in int() constructor converts strings to integers. The toInteger() method doesn't
exist in Python, integer() isn't a built-in function name, and str() would convert an integer to
a string, which is the opposite of what you need.
Question 7: While reviewing a configuration script, you encounter this line: port_number =
8080 # Default port for the web service. How would you categorize this comment according
to Python conventions?
A) Block comment
B) Inline comment
C) Docstring
D) Multi-line comment
Correct Answer: B) Inline comment
Text following a hash symbol (#) on the same line as executable code constitutes an inline
comment. Block comments typically appear on their own lines before code, docstrings use
triple quotes to describe functions or modules, and Python doesn't have formal multi-line
comment syntax.
Question 8: A script contains the mathematical expression result = 15 // 4. What integer value
does the variable result hold after execution?
A) 3.75
B) 3
C) 4
D) 3.0
Correct Answer: B) 3