Docsity

WGU D522 Python for IT Automation – Objective Assessment (OA): Comprehensive Practice Ques, Exams of Nursing

Toggle sidebar
bg1
WGU D522 Python for IT Automation – Objective
Assessment (OA): Comprehensive Practice Questions with
Verified Answers & Detailed Rationales – Covers All Core
Competencies (Python Fundamentals, Data Types, Control
Flow, Functions, File Handling, Error Handling, Automation
Scripting, APIs, Regex, Data Structures) – Latest Exam
Blueprint
--- SECTION 1: PYTHON FUNDAMENTALS & SYNTAX ---
--- QUESTION 1 ---
What are the traits of imperative/procedural programming?
A) Organizes code around objects, which encapsulate data and behavior
B) Emphasizes the use of functions and immutable data for computation
C) Focuses on describing a sequence of steps to perform a task
D) Describes what the program should accomplish without specifying how
ANSWER: C
RATIONALE: Imperative/procedural programming focuses on describing a sequence
of steps to perform a task. It uses statements that change program state and
explicitly defines the "how" of achieving a result.[reference:2][reference:3]
--- QUESTION 2 ---
What are the traits of Object-Oriented Programming (OOP)?
A) Focuses on describing a sequence of steps to perform a task
B) Organizes code around objects, which encapsulate data and behavior
C) Emphasizes the use of functions and immutable data for computation
D) Defines a set of logical conditions and lets the system deduce solutions
ANSWER: B
RATIONALE: Object-Oriented Programming organizes code using objects that
contain both data (attributes) and behaviors (methods). Key principles include
encapsulation, inheritance, and polymorphism.[reference:4][reference:5]
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download WGU D522 Python for IT Automation – Objective Assessment (OA): Comprehensive Practice Ques and more Exams Nursing in PDF only on Docsity!

WGU D522 Python for IT Automation – Objective

Assessment (OA): Comprehensive Practice Questions with

Verified Answers & Detailed Rationales – Covers All Core

Competencies (Python Fundamentals, Data Types, Control

Flow, Functions, File Handling, Error Handling, Automation

Scripting, APIs, Regex, Data Structures) – Latest Exam

Blueprint

--- SECTION 1: PYTHON FUNDAMENTALS & SYNTAX ---

--- QUESTION 1 ---

What are the traits of imperative/procedural programming? A) Organizes code around objects, which encapsulate data and behavior B) Emphasizes the use of functions and immutable data for computation C) Focuses on describing a sequence of steps to perform a task D) Describes what the program should accomplish without specifying how ANSWER: C RATIONALE: Imperative/procedural programming focuses on describing a sequence of steps to perform a task. It uses statements that change program state and explicitly defines the "how" of achieving a result.[reference:2][reference:3] --- QUESTION 2 --- What are the traits of Object-Oriented Programming (OOP)? A) Focuses on describing a sequence of steps to perform a task B) Organizes code around objects, which encapsulate data and behavior C) Emphasizes the use of functions and immutable data for computation D) Defines a set of logical conditions and lets the system deduce solutions ANSWER: B RATIONALE: Object-Oriented Programming organizes code using objects that contain both data (attributes) and behaviors (methods). Key principles include encapsulation, inheritance, and polymorphism.[reference:4][reference:5]

--- QUESTION 3 ---

What are the traits of functional programming? A) Focuses on describing a sequence of steps to perform a task B) Organizes code around objects, which encapsulate data and behavior C) Emphasizes the use of functions and immutable data for computation D) Describes what the program should accomplish without specifying how ANSWER: C RATIONALE: Functional programming treats computation as the evaluation of mathematical functions. It avoids changing state and mutable data, emphasizing pure functions that produce outputs based solely on inputs.[reference:6] [reference:7] --- QUESTION 4 --- What are the traits of declarative programming? A) Focuses on describing a sequence of steps to perform a task B) Organizes code around objects, which encapsulate data and behavior C) Emphasizes the use of functions and immutable data for computation D) Describes what the program should accomplish without specifying how ANSWER: D RATIONALE: Declarative programming describes what the program should accomplish without specifying how to achieve it. SQL and HTML are examples of declarative languages.[reference:8][reference:9] --- QUESTION 5 --- What are the traits of event-driven programming? A) Focuses on describing a sequence of steps to perform a task B) Organizes code around objects, which encapsulate data and behavior C) Emphasizes the use of functions and immutable data for computation

--- QUESTION 8 ---

Why might a programmer use comments for 'Preventing Execution'? A) To make the code run faster B) To temporarily disable lines or blocks of code C) To permanently delete code D) To create documentation ANSWER: B RATIONALE: Programmers use comments to temporarily disable lines or blocks of code, often for debugging or testing purposes, without deleting the code. [reference:16][reference:17] --- QUESTION 9 --- What is the primary use of whitespace in Python? A) To increase the file size B) To separate words in strings C) To define the structure and hierarchy of the code D) To improve the visual appearance only ANSWER: C RATIONALE: Whitespace in Python is used to define the structure and hierarchy of the code. It is not just for visual appearance; it is syntactically significant. [reference:18][reference:19] --- QUESTION 10 --- What does Python use to define the scope of control flow statements and structures like functions and classes? A) Curly braces {} B) Parentheses () C) Indentation D) Semicolons ;

ANSWER: C

RATIONALE: Python uses indentation to define the scope of control flow statements and structures like functions and classes.[reference:20][reference:21] --- QUESTION 11 --- What is the purpose of the input() function in Python? A) To output data to the console B) To capture user input and store it as a string C) To convert data types D) To read files from the disk ANSWER: B RATIONALE: The input() function captures user input from the console and stores it as a string.[reference:22][reference:23] --- QUESTION 12 --- What does the format() method do in Python? A) It converts a string to a number B) It enhances output formatting by embedding variables in strings C) It deletes a variable D) It checks the type of a variable ANSWER: B RATIONALE: The format() method enhances output formatting by embedding variables in strings. Although f-strings are easier to read, format() is still widely used.[reference:24][reference:25] --- QUESTION 13 --- What is the purpose of the print() function in Python? A) To capture user input

What does the float() function do in Python? A) Converts a value to a string B) Converts a value to an integer C) Converts a value to a floating-point number D) Returns the absolute value ANSWER: C RATIONALE: The float() function converts a value to a floating-point number. [reference:32][reference:33] --- QUESTION 17 --- What does the str() function do in Python? A) Converts a value to a string B) Converts a value to an integer C) Converts a value to a floating-point number D) Returns the length of a sequence ANSWER: A RATIONALE: The str() function converts a value to a string.[reference:34] [reference:35] --- QUESTION 18 --- What does the len() function do in Python? A) Converts a value to an integer B) Determines the length of a sequence (string, list, tuple) C) Returns the maximum value from a sequence D) Returns the absolute value of a number ANSWER: B RATIONALE: The len() function determines the length of a sequence (string, list, tuple).[reference:36][reference:37]

--- QUESTION 19 ---

What does the max() function do in Python? A) Returns the maximum value from a sequence B) Returns the minimum value from a sequence C) Calculates the sum of elements in a sequence D) Returns the length of a sequence ANSWER: A RATIONALE: The max() function returns the maximum value from a sequence. [reference:38][reference:39] --- QUESTION 20 --- What does the min() function do in Python? A) Returns the maximum value from a sequence B) Returns the minimum value from a sequence C) Calculates the sum of elements in a sequence D) Returns the length of a sequence ANSWER: B RATIONALE: The min() function returns the minimum value from a sequence. [reference:40][reference:41] --- QUESTION 21 --- What does the sum() function do in Python? A) Returns the maximum value from a sequence B) Returns the minimum value from a sequence C) Calculates the sum of elements in a sequence D) Returns the absolute value of a number

D) ANSWER: A RATIONALE: In Python, 42 is an integer literal, so its type is int. The type() function returns the class of the object.[reference:47] --- QUESTION 25 --- Which of the following correctly converts the string "123" to an integer? A) int("123") B) str("123") C) float("123") D) chr("123") ANSWER: A RATIONALE: The int() constructor converts a numeric string to an integer. str() returns a string, float() gives a float, and chr() is used for Unicode code points. [reference:48] --- QUESTION 26 --- What is the result of 17 // 4? A) 4. B) 4 C) 5 D) 4. ANSWER: B RATIONALE: The // operator performs floor division (integer division), discarding the remainder. 17 // 4 = 4.[reference:49] --- QUESTION 27 --- What is the result of 17 / 4 in Python?

A) 4

B) 4.

C) 4.

D) 5

ANSWER: B

RATIONALE: The / operator performs float division, returning a floating-point result. 17 / 4 = 4.25. --- QUESTION 28 --- What is the result of 17 % 4? A) 4 B) 1 C) 4. D) 0 ANSWER: B RATIONALE: The % operator returns the remainder of the division. 17 % 4 = 1. --- QUESTION 29 --- What is the result of 2 ** 3? A) 6 B) 8 C) 9 D) 5 ANSWER: B RATIONALE: The ** operator performs exponentiation. 2 ** 3 = 2 * 2 * 2 = 8. --- QUESTION 30 ---

RATIONALE: Python's built-in numeric types include int, float, and complex. "rational" is not a primitive type in Python; fractions.Fraction can be used but is not a core type.[reference:51] --- QUESTION 33 --- What does the term "dynamically-typed" mean in Python? A) Variables must be declared with a specific type before use B) The interpreter determines the type of variable during runtime C) Python code is compiled before execution D) Types cannot be changed after assignment ANSWER: B RATIONALE: Python is dynamically-typed, meaning the interpreter determines the type of variable during runtime. This allows variables to be reassigned to different types.[reference:52] --- QUESTION 34 --- What is the proper way to create a single-line comment in Python? A) // This is a comment B) /* This is a comment / C) # This is a comment D) ANSWER: C RATIONALE: In Python, the # symbol is used to create a single-line comment. Everything after the # on that line is ignored by the interpreter. --- QUESTION 35 --- What is the proper way to create a multi-line comment in Python? A) / This is a comment */ B)

C) # This is a comment (on multiple lines with #) D) """This is a multi-line comment""" (using triple quotes) ANSWER: D RATIONALE: While Python does not have a specific multi-line comment syntax, triple quotes (""" or ''') are often used for multi-line comments or docstrings. --- QUESTION 36 --- Which of the following is a valid variable name in Python? A) 2nd_place B) my-variable C) _private D) class ANSWER: C RATIONALE: Variable names in Python must start with a letter or underscore, and can only contain letters, numbers, or underscores. "class" is a reserved keyword. [reference:53] --- QUESTION 37 --- Which of the following is NOT a valid variable name in Python? A) my_var B) _var C) var D) 123var ANSWER: D RATIONALE: Variable names cannot start with a number. "123var" starts with a number, making it invalid.[reference:54] --- QUESTION 38 ---

--- QUESTION 41 ---

What is the output of: print(True and False)? A) True B) False C) 1 D) 0 ANSWER: B RATIONALE: The "and" operator returns True only if both operands are True. True and False evaluates to False. --- QUESTION 42 --- What is the output of: print(True or False)? A) True B) False C) 1 D) 0 ANSWER: A RATIONALE: The "or" operator returns True if at least one operand is True. True or False evaluates to True. --- QUESTION 43 --- What is the output of: print(not True)? A) True B) False C) 1 D) 0

ANSWER: B

RATIONALE: The "not" operator negates the boolean value. not True evaluates to False. --- QUESTION 44 --- Which statement checks if a variable age is between 18 and 65 inclusive? A) 18 < age < 65 B) 18 <= age <= 65 C) age >= 18 and age <= 65 D) Both B and C are correct ANSWER: D RATIONALE: Both "18 <= age <= 65" and "age >= 18 and age <= 65" correctly check if age is between 18 and 65 inclusive.[reference:55] --- QUESTION 45 --- What is the purpose of the backslash () in a Python string? A) To start a comment B) To escape special characters C) To concatenate strings D) To end a line ANSWER: B RATIONALE: The backslash () is used as an escape character in Python strings to include special characters (e.g., \n for newline, \t for tab). --- SECTION 2: DATA TYPES & VARIABLES --- --- Questions 46–85 --- --- QUESTION 46 --- Which Python data type represents an ordered, mutable sequence?

--- QUESTION 49 ---

Which Python data type is a mutable mapping of key-value pairs? A) list B) tuple C) set D) dict ANSWER: D RATIONALE: A dictionary (dict) is a mutable mapping of key-value pairs. Keys must be unique and immutable.[reference:59] --- QUESTION 50 --- What is the output of: print(type([1, 2, 3]))? A) B) C) D) ANSWER: B RATIONALE: [1, 2, 3] is a list literal, so its type is list. --- QUESTION 51 --- What is the output of: print(type((1, 2, 3)))? A) B) C) D) ANSWER: A

RATIONALE: (1, 2, 3) is a tuple literal, so its type is tuple. --- QUESTION 52 --- What is the output of: print(type({1, 2, 3}))? A) B) C) D) ANSWER: C RATIONALE: {1, 2, 3} is a set literal, so its type is set. --- QUESTION 53 --- What is the output of: print(type({'a': 1, 'b': 2}))? A) B) C) D) ANSWER: D RATIONALE: {'a': 1, 'b': 2} is a dictionary literal, so its type is dict. --- QUESTION 54 --- What is the output of: bool(0)? A) True B) False C) 0 D) Error ANSWER: B