Escrito por estudiantes que aprobaron Inmediatamente disponible después del pago Leer en línea o como PDF ¿Documento equivocado? Cámbialo gratis 4,6 TrustPilot
logo-home
Examen

WGU D522 Python for IT Automation ACTUAL OBJECTIVE ASSESSMENT PRACTICE 2026/2027 | Verified Code-Centric & Scenario-Based Questions and Answers | Grade A Target | Pass Guaranteed

Puntuación
-
Vendido
-
Páginas
55
Grado
A+
Subido en
07-02-2026
Escrito en
2025/2026

WGU D522 Python for IT Automation ACTUAL OBJECTIVE ASSESSMENT PRACTICE 2026/2027 | Verified Code-Centric & Scenario-Based Questions and Answers | Grade A Target | Pass Guaranteed

Institución
WGU D522
Grado
WGU D522

Vista previa del contenido

WGU D522 Python for IT Automation ACTUAL
OBJECTIVE ASSESSMENT PRACTICE 2026/2027 | Verified
Code-Centric & Scenario-Based Questions and Answers
| Grade A Target | Pass Guaranteed
SECTION 1: Python Foundations & Scripting Environment (Questions 1-10)



Q1: An IT automation script needs to process a list of server hostnames and ensure no
duplicates exist while maintaining the original order of first appearance. Which Python code
segment accomplishes this most efficiently?

A. unique_servers = list(set(server_list)) B. unique_servers = sorted(set(server_list),
key=server_list.index) C. seen = set(); unique_servers = [x for x in server_list if not (x in seen or
seen.add(x))] [CORRECT] D. unique_servers = []; [unique_servers.append(x) for x in server_list if
x not in unique_servers]

Correct Answer: C

Rationale: Option C uses a set for O(1) membership testing while preserving order through a list
comprehension with side effect. The seen set tracks encountered items; the or short-circuit
ensures add() only executes if x not in seen is True. This achieves O(n) time complexity. Option A
loses original order (sets are unordered). Option B is O(n²) due to index() calls. Option D is O(n²)
due to linear not in searches on a growing list. For IT automation processing large infrastructure
inventories, Option C provides optimal performance. [CORRECT: C]



Q2: A system administrator is writing a script to handle potential file access errors. Which
exception handling structure follows Python best practices for catching specific errors while
avoiding bare except clauses?

A.

Python

Copy

try:

with open('/etc/passwd', 'r') as f:

, data = f.read()

except:

print("Error occurred")

B.

Python

Copy

try:

with open('/etc/passwd', 'r') as f:

data = f.read()

except FileNotFoundError as e:

logger.error(f"Password file missing: {e}")

except PermissionError as e:

logger.error(f"Insufficient permissions: {e}")

except Exception as e:

logger.critical(f"Unexpected error: {e}")

raise

``` [CORRECT]



C.

```python

try:

f = open('/etc/passwd', 'r')

data = f.read()

except (FileNotFoundError, PermissionError, OSError):

print("File access failed")

finally:

, f.close()

D.

Python

Copy

try:

data = open('/etc/passwd', 'r').read()

except Exception:

pass

Correct Answer: B

Rationale: Option B demonstrates proper exception hierarchy: specific exceptions
(FileNotFoundError, PermissionError) are caught first for targeted handling, followed by a
general Exception handler that logs and re-raises unexpected errors. This follows PEP 8 and the
Zen of Python ("Errors should never pass silently"). The with statement ensures proper resource
cleanup. Option A uses a bare except, catching KeyboardInterrupt and SystemExit
inappropriately. Option C risks UnboundLocalError if open() fails before f is assigned. Option D
silently suppresses all errors, masking critical failures in automation scripts. [CORRECT: B]



Q3: [Code Analysis] What is the output of the following script when executed on a Linux
system?

Python

Copy

#!/usr/bin/env python3

import sys



def main():

if len(sys.argv) < 2:

print("Usage: script.py <hostname>", file=sys.stderr)

sys.exit(1)

, hostname = sys.argv[1]

domain_parts = hostname.split('.')



if len(domain_parts) >= 2:

print(f"Domain: {'.'.join(domain_parts[-2:])}")

else:

print("Invalid FQDN")



if __name__ == "__main__":

main()

Executed as: python3 script.py web01.prod.example.com

A. Domain: web01.prod B. Domain: example.com [CORRECT] C. Domain: prod.example.com D.
Usage: script.py <hostname>

Correct Answer: B

Rationale: The script extracts the last two domain components. hostname.split('.') produces
['web01', 'prod', 'example', 'com']. The slice [-2:] selects ['example', 'com'], which join()
combines as "example.com". This is a common pattern in IT automation for extracting domain
information from FQDNs. Option A incorrectly takes the first two elements. Option C takes
elements 1-3 (index 1 onward). Option D would only occur with no command-line arguments
provided. [CORRECT: B]



Q4: Which shebang line should be used for a Python 3 automation script intended to run across
heterogeneous Unix-like environments (Linux, macOS, BSD) where Python may be installed in
various locations?

A. #!/bin/python3 B. #!/usr/bin/python3 C. #!/usr/bin/env python3 [CORRECT] D. #!python3

Correct Answer: C

Rationale: #!/usr/bin/env python3 uses the env command to locate python3 in the user's
$PATH, ensuring portability across systems where Python may be in /usr/bin, /usr/local/bin,

Escuela, estudio y materia

Institución
WGU D522
Grado
WGU D522

Información del documento

Subido en
7 de febrero de 2026
Número de páginas
55
Escrito en
2025/2026
Tipo
Examen
Contiene
Preguntas y respuestas

Temas

$16.99
Accede al documento completo:

¿Documento equivocado? Cámbialo gratis Dentro de los 14 días posteriores a la compra y antes de descargarlo, puedes elegir otro documento. Puedes gastar el importe de nuevo.
Escrito por estudiantes que aprobaron
Inmediatamente disponible después del pago
Leer en línea o como PDF

Conoce al vendedor
Seller avatar
EMPRESS254
1.0
(1)

Conoce al vendedor

Seller avatar
EMPRESS254 Chamberlain College Of Nursing
Seguir Necesitas iniciar sesión para seguir a otros usuarios o asignaturas
Vendido
6
Miembro desde
6 meses
Número de seguidores
0
Documentos
646
Última venta
20 horas hace
Empress

One stop shop for all all study materials, Study guides,Exams and all assignments and homeworks.

1.0

1 reseñas

5
0
4
0
3
0
2
0
1
1

Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes