• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 3 out of 20 pages
Exam (elaborations)

WGU D522 Python for IT Automation Objective Assessment 2026/2027 – Questions and Answers | 100% Verified | Detailed Rationales – Pass Guaranteed – A+ Graded

Document preview thumbnail
Preview 3 out of 20 pages

WGU D522 OA 2026/2027 – Questions with Answers | 100% Correct | Python Programming, IT Automation, Scripting, File Management | Graded A+ Verified | APIs, Error Handling, Version Control, Task Automation | Detailed Rationales | Verified Correct Answers – Pass Guaranteed – Instant Download

Content preview

IT AUTOMATION EXAM PREP




WGU D522 Objective Assessment
(New 2026/2027 Update)
Python for IT Automation
2026/2027 ACTUAL EXAM TEST BANK
WITH REAL EXAM QUESTIONS AND
100% CORRECT VERIFIED ANSWERS
(GUARANTEED PASS!!)

Aligned to WGU Content Outline • IT Automation Level



A+ QUESTIONS 5 SECTIONS 100%
VERIFIED COMPLETE RATIONALES




CATEGORIES

SECTION 1 — Python Fundamentals & Syntax

SECTION 2 — Data Structures & Control Flow

SECTION 3 — File Handling & OS Automation

SECTION 4 — Network Automation & Sockets

SECTION 5 — Error Handling, Debugging & Scripting Best Practices




STUVIAACTUALEXAM

, SECTION 1: Python Fundamentals & Syntax

Q1. An IT administrator is writing a script that will run nightly to inventory servers. The first line of the script must declare
the Python interpreter so the operating system can execute it without explicitly calling python. Which shebang line
correctly identifies the Python 3 interpreter on a typical Linux system?
A. #!/usr/bin/env python3
B. #!python3
C. #!/bin/python
D. # -*- coding: utf-8 -*-
Correct Answer: A
Rationale: The portable shebang #!/usr/bin/env python3 locates the Python 3 interpreter via the PATH environment variable and is the
recommended form for cross-system scripts. Options B and C either omit the full path or point to a non-standard location, while the
coding declaration is unrelated to interpreter selection.


Q2. A junior engineer pastes a multi-line configuration block into a Python script and notices that the code under an if
statement never executes even though the condition evaluates to True. The engineer used spaces for some lines and a
single tab for others. What is the most likely root cause of the silent failure?
A. Python treats inconsistent indentation as a logical block error and skips the indented suite at runtime
B. Mixing tabs and spaces raises IndentationError only when the block is empty
C. The interpreter silently coerces tabs to four spaces, changing the intended nesting
D. Inconsistent use of tabs and spaces produces an IndentationError that prevents the script from starting
Correct Answer: D
Rationale: Python 3 strictly forbids mixing tabs and spaces for indentation and raises IndentationError at parse time, stopping
execution before any code runs. The other choices misrepresent how the interpreter handles whitespace or invent silent runtime
behavior that does not exist.


Q3. While reviewing a colleague’s automation script, you encounter the statement x = 5; y = 5; print(x is y). On a
standard CPython interpreter the output is True. What does the is operator actually compare, and why can the result be
True for small integers?
A. It compares object identity (memory addresses); CPython interns small integers so both names refer to the same object
B. It compares values only; the is operator is an alias for == when both operands are integers
C. It compares types; because both variables are int the result is always True
D. It performs a bitwise comparison of the underlying C long values
Correct Answer: A
Rationale: The is operator tests object identity. CPython maintains a cache of small integer objects (−5 to 256), so two variables bound
to the same small integer value share a single object and therefore return True for is. Equality of value is tested with ==, not is.


Q4. A network engineer needs a constant that represents the maximum number of concurrent SSH sessions allowed by
policy. The value must never be reassigned accidentally later in the script. Which Python convention and language
feature best communicates and partially enforces this intent?
A. Wrap the integer inside a tuple of length one and never unpack it
B. Use the const keyword before the assignment so the interpreter raises an error on reassignment
C. Declare the name in ALL_CAPS and treat it as a constant by convention; Python has no true immutable binding for
integers
D. Store the value in a module-level __constant__ dictionary that the interpreter protects
Correct Answer: C
Rationale: Python has no const keyword or true constant objects for built-in types. The community convention of writing names in
ALL_CAPS signals that the value should not be reassigned. The other options invent language features that do not exist.




STUVIAACTUALEXAM • Page 2

, Q5. You are debugging a script that builds a configuration string for a firewall rule. The engineer wrote: rule = "permit tcp
any any eq " + port where port is an integer variable. The script raises TypeError. What is the cleanest Python 3 fix that
also keeps the code readable?
A. rule = f"permit tcp any any eq {port}"
B. rule = "permit tcp any any eq " + str(port) using only the + operator and an explicit cast
C. rule = "permit tcp any any eq %s" % port (old-style formatting)
D. rule = "permit tcp any any eq {}".format(port) is the only acceptable modern approach
Correct Answer: A
Rationale: f-strings (formatted string literals) are the preferred, most readable way to interpolate values in Python 3.6+. They evaluate
the expression inside the braces and convert it automatically. While the other options can work, the f-string is the cleanest modern
solution.


Q6. A script must accept a hostname from the command line when the automation job is launched. The engineer wants
to keep the code compatible with both interactive testing and scheduled runs. Which module and function provide the
most idiomatic way to obtain the arguments that follow the script name?
A. import os; hostname = os.environ["HOSTNAME"]
B. import sys; hostname = sys.argv[1]
C. import argparse; hostname = argparse.get_argument(1)
D. import getopt; hostname = getopt.getopt()[0]
Correct Answer: B
Rationale: sys.argv is a list whose first element is the script name and subsequent elements are the positional arguments supplied on
the command line. For simple cases this is the most direct and commonly used approach. argparse is more powerful for complex CLIs
but is heavier for a single required argument.


Q7. An automation developer writes a helper function that should return both the number of lines processed and a list of
error messages. The function currently ends with return count, errors. What data structure does the caller actually
receive, and how should the caller unpack it?
A. A dictionary with keys "count" and "errors"
B. A list; the caller must index the result as result[0] and result[1]
C. A tuple; the caller can write count, errors = process_file(path)
D. Two separate return values that must be captured with two consecutive assignment statements
Correct Answer: C
Rationale: Python functions that appear to return multiple values actually return a single tuple. Tuple unpacking on the left-hand side of
an assignment is the idiomatic way to receive those values. The other descriptions mischaracterize the actual return type.


Q8. While examining a legacy script you find the statement print "Processing host", host. The script was written years
ago and now fails under Python 3. What is the precise reason for the failure and the minimal change required to restore
functionality?
A. The comma operator is no longer supported; rewrite as a single concatenated string
B. print became a function; change to print("Processing host", host)
C. String literals require the u prefix in Python 3
D. print statements must be indented under a main guard
Correct Answer: B
Rationale: In Python 2 print was a statement; in Python 3 it is a built-in function that requires parentheses. Adding the parentheses is
the minimal, correct migration step. The other explanations invent language changes that did not occur.




STUVIAACTUALEXAM • Page 3

Document information

Uploaded on
September 11, 2026
Number of pages
20
Written in
2026/2027
Type
Exam (elaborations)
Contains
Questions & answers
$16.99

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
STUVIAACTUALEXAMS
3.5
(176)
Sold
1342
Followers
209
Items
10272
Last sold
1 hour ago



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions