WGU D522 OBJECTIVE ASSESSMENT (NEW UPDATE)
PYTHON FOR IT AUTOMATION | QS & AS | GRADE A | 100%
CORRECT (VERIFIED ANSWERS)
TABLE OF CONTENTS
Section Domain Approx. Page
Questions Reference
1 Python Data Structures (Lists, Tuples, 15 Q1-15
Sets, Dictionaries)
2 Control Flow and Loops 15 Q16-30
3 Functions and Modules 15 Q31-45
4 File Handling 10 Q46-55
5 Error Handling 9 Q56-64
6 Automation Scripting 26 Q65-90
7 Advanced File Handling 15 Q91-105
8 Data Formats, Modules, and Best 15 Q106-120
Practices
9 Advanced Automation Scripting 20 Q121-140
10 Networking and Web Automation 15 Q141-155
11 System Administration and Security 15 Q156-170
12 Data Serialization and APIs 15 Q171-185
13 Testing, Debugging, and Packaging 15 Q186-200
,SECTION 1: PYTHON DATA STRUCTURES (LISTS, TUPLES, SETS,
DICTIONARIES)
Question 1
Which of the following data structures in Python is immutable,
meaning its elements cannot be changed after creation?
A. List
B. Dictionary
C. Set
D. Tuple
D. Tuple
Rationale: Tuples are immutable sequences, typically used to store
collections of heterogeneous data. Lists, dictionaries, and sets are
mutable, meaning their contents can be altered after they are created.
Question 2
What is the primary advantage of using a dictionary in Python for
automation scripting?
A. It maintains insertion order and allows duplicate keys.
B. It allows fast lookups of values based on unique keys.
C. It stores elements in a contiguous block of memory for fast indexing.
D. It automatically sorts its keys in ascending order.
B. It allows fast lookups of values based on unique keys.
Rationale: Dictionaries are implemented as hash tables, providing O(1)
average time complexity for lookups, insertions, and deletions. This
makes them highly efficient for mapping unique keys to specific values.
Question 3
Which method is used to add a new key-value pair to an existing
dictionary?
,A. append()
B. add()
C. insert()
D. update()
D. update()
Rationale: The update() method is used to add multiple key-value pairs
or update existing ones. Alternatively, you can assign a value directly
using square brackets (e.g., dict[key] = value). append() is for lists, add()
is for sets, and insert() is for lists.
Question 4
What will be the output of the following code snippet?
my_set = {1, 2, 2, 3, 4, 4, 5}
print(len(my_set))
A. 7
B. 5
C. 4
D. 6
B. 5
Rationale: Sets in Python are unordered collections of unique elements.
Duplicate values are automatically removed upon creation. Therefore,
the set contains {1, 2, 3, 4, 5}, which has a length of 5.
Question 5
How can you access the value associated with the key 'name' in a
dictionary called 'user' without raising a KeyError if the key does not
exist?
A. user['name']
B. user.get('name')
C. user.fetch('name')
, D. user.value('name')
B. user.get('name')
Rationale: The get() method returns None (or a specified default value)
if the key is not found, preventing a KeyError. Using square brackets
user['name'] will raise a KeyError if the key does not exist.
Question 6
Which of the following statements about Python lists is true?
A. Lists are immutable and cannot be modified.
B. Lists can only contain elements of the same data type.
C. Lists are ordered collections and support indexing.
D. Lists cannot contain duplicate elements.
C. Lists are ordered collections and support indexing.
Rationale: Lists are ordered, mutable sequences that allow duplicate
elements. They can contain elements of varying data types and are
accessed by their index, starting at 0.
Question 7
What is the result of slicing a list my_list = [10, 20, 30, 40, 50] using
my_list[1:4]?
A. [10, 20, 30]
B. [20, 30, 40]
C. [20, 30, 40, 50]
D. [10, 20, 30, 40]
B. [20, 30, 40]
Rationale: List slicing syntax is [start:stop], where start is inclusive and
stop is exclusive. Therefore, my_list[1:4] starts at index 1 (20) and goes
up to, but does not include, index 4 (50), resulting in [20, 30, 40].
PYTHON FOR IT AUTOMATION | QS & AS | GRADE A | 100%
CORRECT (VERIFIED ANSWERS)
TABLE OF CONTENTS
Section Domain Approx. Page
Questions Reference
1 Python Data Structures (Lists, Tuples, 15 Q1-15
Sets, Dictionaries)
2 Control Flow and Loops 15 Q16-30
3 Functions and Modules 15 Q31-45
4 File Handling 10 Q46-55
5 Error Handling 9 Q56-64
6 Automation Scripting 26 Q65-90
7 Advanced File Handling 15 Q91-105
8 Data Formats, Modules, and Best 15 Q106-120
Practices
9 Advanced Automation Scripting 20 Q121-140
10 Networking and Web Automation 15 Q141-155
11 System Administration and Security 15 Q156-170
12 Data Serialization and APIs 15 Q171-185
13 Testing, Debugging, and Packaging 15 Q186-200
,SECTION 1: PYTHON DATA STRUCTURES (LISTS, TUPLES, SETS,
DICTIONARIES)
Question 1
Which of the following data structures in Python is immutable,
meaning its elements cannot be changed after creation?
A. List
B. Dictionary
C. Set
D. Tuple
D. Tuple
Rationale: Tuples are immutable sequences, typically used to store
collections of heterogeneous data. Lists, dictionaries, and sets are
mutable, meaning their contents can be altered after they are created.
Question 2
What is the primary advantage of using a dictionary in Python for
automation scripting?
A. It maintains insertion order and allows duplicate keys.
B. It allows fast lookups of values based on unique keys.
C. It stores elements in a contiguous block of memory for fast indexing.
D. It automatically sorts its keys in ascending order.
B. It allows fast lookups of values based on unique keys.
Rationale: Dictionaries are implemented as hash tables, providing O(1)
average time complexity for lookups, insertions, and deletions. This
makes them highly efficient for mapping unique keys to specific values.
Question 3
Which method is used to add a new key-value pair to an existing
dictionary?
,A. append()
B. add()
C. insert()
D. update()
D. update()
Rationale: The update() method is used to add multiple key-value pairs
or update existing ones. Alternatively, you can assign a value directly
using square brackets (e.g., dict[key] = value). append() is for lists, add()
is for sets, and insert() is for lists.
Question 4
What will be the output of the following code snippet?
my_set = {1, 2, 2, 3, 4, 4, 5}
print(len(my_set))
A. 7
B. 5
C. 4
D. 6
B. 5
Rationale: Sets in Python are unordered collections of unique elements.
Duplicate values are automatically removed upon creation. Therefore,
the set contains {1, 2, 3, 4, 5}, which has a length of 5.
Question 5
How can you access the value associated with the key 'name' in a
dictionary called 'user' without raising a KeyError if the key does not
exist?
A. user['name']
B. user.get('name')
C. user.fetch('name')
, D. user.value('name')
B. user.get('name')
Rationale: The get() method returns None (or a specified default value)
if the key is not found, preventing a KeyError. Using square brackets
user['name'] will raise a KeyError if the key does not exist.
Question 6
Which of the following statements about Python lists is true?
A. Lists are immutable and cannot be modified.
B. Lists can only contain elements of the same data type.
C. Lists are ordered collections and support indexing.
D. Lists cannot contain duplicate elements.
C. Lists are ordered collections and support indexing.
Rationale: Lists are ordered, mutable sequences that allow duplicate
elements. They can contain elements of varying data types and are
accessed by their index, starting at 0.
Question 7
What is the result of slicing a list my_list = [10, 20, 30, 40, 50] using
my_list[1:4]?
A. [10, 20, 30]
B. [20, 30, 40]
C. [20, 30, 40, 50]
D. [10, 20, 30, 40]
B. [20, 30, 40]
Rationale: List slicing syntax is [start:stop], where start is inclusive and
stop is exclusive. Therefore, my_list[1:4] starts at index 1 (20) and goes
up to, but does not include, index 4 (50), resulting in [20, 30, 40].