• ¿Documento equivocado? Cámbialo gratis
  • Escrito por estudiantes que aprobaron
  • Inmediatamente disponible después del pago
  • Leer en línea o como PDF
Vender
¿Dónde estudias?
Tu idioma
Document preview thumbnail
Vista previa 4 fuera de 54 páginas
Examen

Wgu D522 Python For It Automation Secure Coding Secrets And Logging Quick Reference Gitlab Ci/Cd And Security Checklists Final Exam Questions And Correct Answers Plus Rationales| Instant Download

Document preview thumbnail
Vista previa 4 fuera de 54 páginas

Wgu D522 Python For It Automation Secure Coding Secrets And Logging Quick Reference Gitlab Ci/Cd And Security Checklists Final Exam Questions And Correct Answers Plus Rationales| Instant Download

Vista previa del contenido

Wgu D522 Python For It Automation Secure Coding Secrets
And Logging Quick Reference Gitlab Ci/Cd And Security
Checklists Final Exam Questions And Correct Answers Plus
Rationales| Instant Download

This exam assesses advanced Python programming concepts essential for IT automation, including data
structures, control flow, functions, modules, error handling, file I/O, and integration with system tasks. It
emphasizes secure coding practices, efficient scripting, and automation of routine IT operations using Python 3.x.
It contains 148 multiple-choice questions, each with four distractors and a fully worked rationale that explains
why the keyed answer is correct. Content is organized into 10 focused sections: Python Fundamentals for IT
Automation, Secure Coding Practices in Python, Secrets Management and Credential Handling, Logging and
Monitoring in Python Applications, GitLab CI/CD Pipelines and Configuration, CI/CD Security and DevSecOps
Integration, Security Checklists and Compliance Controls, Automation Scripting and Error Handling, Access
Control and Data Protection, Testing, Validation, and Deployment Safeguards. Targeted learning outcomes
include: Design and implement Python scripts to automate complex IT tasks using appropriate data structures
and control flow.; Apply secure coding principles and error handling to create robust automation solutions.;
Utilize Python modules and libraries for system administration, file processing, and network operations.. Every
item has been reviewed for clinical accuracy, current guidelines, and clarity so that students can study with
confidence and self-correct as they work through the bank. Use it as a high-yield review immediately before the
exam, or as a structured practice tool during the unit - the rationales double as concise teaching notes. The

Section 1: Python Fundamentals for IT Automation (Questions 1-14)

1 What is the output of: print([x*2 for x in range(3) if x%2==0])?
A) [0, 4]
B) [0, 2, 4]
C) [0, 2]
D) [2, 4]
Answer: A
Rationale: The list comprehension iterates x=0,1,2; condition x%2==0 keeps 0
and 2; multiplying by 2 yields [0,4]. Other options incorrectly include odd
numbers or omit the multiplication.

2 Which code safely reads a file and ensures closure even if an exception
occurs?
A) f=open('file'); data=f.read(); f.close()
B) with open('file') as f: data=f.read()
C) try: f=open('file'); data=f.read() finally: f.close()
D) data=open('file').read()
Answer: B

,Rationale: The with statement guarantees file closure via context manager, even
on exceptions. Option A lacks exception safety; C is correct but more verbose;
D leaves file open.

3 In Python, what is the primary purpose of the __name__ == '__main__'
check?
A) To define the main function
B) To execute code only when script is run directly
C) To import modules conditionally
D) To set the script's name
Answer: B
Rationale: The check prevents code from running when the module is imported,
allowing reuse. It does not define a main function or set the name; it controls
execution context.

4 What does the expression 'a,b = b,a' accomplish in Python?
A) Assigns b to a and a to b simultaneously
B) Creates a tuple (b,a) and assigns to a,b
C) Raises a syntax error
D) Swaps values using a temporary variable
Answer: A
Rationale: Python evaluates right side first, then unpacks, swapping values
without a temporary. It is not a syntax error; it is a tuple assignment.
5 Which method is used to remove and return an arbitrary element from a set?
A) remove()
B) discard()
C) pop()
D) clear()
Answer: C
Rationale: set.pop() removes and returns an arbitrary element. remove()
removes specified element and raises KeyError if absent; discard() removes
without error; clear() empties set.

6 What is the result of: print(3 * 'ab')?
A) ababab

,B) ab3
C) TypeError
D) ab ab ab
Answer: A
Rationale: String repetition with * repeats the string. 3 * 'ab' yields 'ababab'.
Other options misinterpret operator or type.

7 Which statement about Python's pass statement is correct?
A) It terminates the program
B) It acts as a placeholder and does nothing
C) It skips the current iteration
D) It raises an exception
Answer: B
Rationale: pass is a null operation; it is used when a statement is syntactically
required but no action is needed. It does not terminate, skip, or raise.

8 What is the output of: print(len({'a':1, 'b':2}.keys()))?
A) 1
B) 2
C) 3
D) Error
Answer: B
Rationale: dict.keys() returns a view of keys; len() returns number of keys,
which is 2. No error occurs.

9 Which code correctly catches multiple exceptions (ValueError and
TypeError) in Python 3?
A) except ValueError, TypeError:
B) except (ValueError, TypeError):
C) except ValueError and TypeError:
D) except ValueError or TypeError:
Answer: B
Rationale: Use a tuple of exceptions to catch multiple. Option A is invalid
syntax; C and D use logical operators incorrectly.

, 10 In Python, which construct best ensures atomic replacement of a config file
during automation?
A) open(path, 'w') then write, then close
B) os.replace(tmp_path, path) after writing and fsyncing tmp file
C) shutil.copyfile(tmp_path, path) then os.remove(tmp_path)
D) path.write_text(data) directly to the target path
Answer: B
Rationale: os.replace is atomic on POSIX and Windows when source and
destination are on the same filesystem, and fsync ensures durability. Direct
writes (A, D) and copyfile (C) are non-atomic and can leave partial files if
interrupted.

11 Which Python idiom correctly captures a subprocess's output and fails
loudly on nonzero exit?
A) subprocess.run(cmd, capture_output=True, check=True)
B) subprocess.call(cmd, shell=True)
C) os.system(cmd)
D) subprocess.Popen(cmd).wait()
Answer: A
Rationale: subprocess.run with capture_output=True collects stdout/stderr and
check=True raises CalledProcessError on failure. call, os.system, and bare
Popen do not raise and do not capture output reliably.
12 A script must iterate over a 10 GB log file without exhausting memory.
Which approach is correct?
A) data = open('log').read().splitlines()
B) for line in open('log'): process(line)
C) lines = list(open('log'))
D) data = open('log').readlines()
Answer: B
Rationale: Iterating over a file object streams line by line with constant
memory. read().splitlines(), list(), and readlines() materialize the entire file in
memory, which is unsafe for a 10 GB file.

13 Which Python construct most reliably prevents command injection when
invoking an external tool with user input?

Información del documento

Subido en
24 de octubre de 2026
Número de páginas
54
Escrito en
2026/2027
Tipo
Examen
Contiene
Preguntas y respuestas
$26.49

¿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

Vendido
6
Seguidores
2
Artículos
620
Última venta
2 días hace



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