Docsity

WGU D522 Python for IT Automation Task 2, Exams of Nursing

Toggle sidebar
bg1
1 | P a g e
WGU D522 Python for IT Automation Task 2 - 2026
Newest Exam Preparation With Complete Questions
And Correct Answers With Rationales Already
Graded A+Brand New Version!!
Section 1: Python Fundamentals
Question 1
Which of the following is the correct syntax for a single-line comment in
Python?
A. // This is a comment
B. /* This is a comment */
C. # This is a comment
D. <!-- This is a comment -->
Correct Answer: C
Explanation: In Python, the hash symbol (#) is used to indicate a
comment. All characters following the # on that line are ignored by the
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 Task 2 and more Exams Nursing in PDF only on Docsity!

WGU D522 Python for IT Automation Task 2 - 2026

Newest Exam Preparation With Complete Questions

And Correct Answers With Rationales Already

Graded A+Brand New Version!!

Section 1: Python Fundamentals Question 1 Which of the following is the correct syntax for a single-line comment in Python? A. // This is a comment B. /* This is a comment */ C. # This is a comment D. Correct Answer: C Explanation: In Python, the hash symbol (#) is used to indicate a comment. All characters following the # on that line are ignored by the

interpreter. Option A is used in languages like C++ and Java for single- line comments, Option B is used in C-style languages for multi-line comments, and Option D is used for comments in HTML. The Python interpreter will raise a syntax error for any of the other options, as they are not recognized comment syntax. Question 2 What is the output of the following Python code? x = 5 y = 2 print(x // y) A. 2. B. 2 C. 3 D. 2. Correct Answer: B Explanation: The // operator in Python is the floor division operator. It divides the first operand by the second and returns the largest integer less than or equal to the result. For 5 // 2, the result of standard division is 2.5, and the floor of 2.5 is 2. Option A is the result of true division (/). Option C would be the result of rounding up or ceiling division. Option D represents a float value, but floor division returns an integer when both operands are integers.

C. "o Aut" D. "Automat" Correct Answer: C Explanation: String slicing uses the syntax [start:stop], where the start index is inclusive and the stop index is exclusive. For the string "IT Automation", the indices are as follows: 0:I, 1:T, 2: (space), 3:o, 4: (space), 5:A, 6:u, 7:t, 8:o, 9:m, 10:a, 11:t, 12:i, 13:o, 14:n. Therefore, name[3:8] starts at index 3 ("o") and stops before index 8 ("o"), resulting in the substring "o Aut". Question 5 Which Python built-in function is used to determine the number of items in a container like a list, tuple, or string? A. size() B. length() C. len() D. count() Correct Answer: C Explanation: The built-in len() function is the standard and correct way to get the number of items in a sequence or collection in Python. It

works with strings, lists, tuples, dictionaries, sets, and other iterable objects. Option A (size()) is not a built-in function in Python. Option B (length()) is not a built-in function. Option D (count()) is a method available for lists and strings, but it counts the occurrences of a specific value, not the total number of items. Question 6 What is the output of the following code? a = [1, 2, 3] b = a b.append(4) print(a) A. [1, 2, 3] B. [1, 2, 3, 4] C. [4] D. [1, 2, 3, [4]] Correct Answer: B Explanation: In Python, when you assign a list to a new variable (b = a), you are not creating a copy of the list. Instead, you are creating a new reference to the same list object in memory. Therefore, any modifications made through b will be reflected in a, and vice versa. When b.append(4) is called, the list is modified in place, resulting in [1, 2, 3, 4]. The print(a) statement outputs the modified list.

D. To check if a variable is defined Correct Answer: A Explanation: The is operator in Python is used to test object identity. It returns True if both operands refer to the same object in memory. This is different from the == operator, which tests for value equality. For instance, a is b checks if a and b are the same object, whereas a == b checks if the contents of a and b are equivalent. Option B describes the == operator, C is assignment (=), and D is not a standard operator check. Question 9 What is the Boolean value of the expression bool(0)? A. True B. False C. None D. 0 Correct Answer: B Explanation: In Python, certain values are considered "falsy" when evaluated in a Boolean context. The integer 0 is one of these falsy values. Other falsy values include None, False, empty sequences (e.g., "", [], ()), and empty mappings ({}). Therefore, bool(0)

evaluates to False. All other non-zero numbers, non-empty containers, and True are considered "truthy". Question 10 Which of the following is the correct way to add a single element to the end of a Python list? A. add() B. insert() C. append() D. extend() Correct Answer: C Explanation: The append() method is the correct way to add a single element to the end of a list in Python. It modifies the list in place. Option A (add()) is a method for sets, not lists. Option B (insert()) can add an element at a specific index but defaults to the beginning if no index is specified. Option D (extend()) is used to add multiple elements from an iterable to the end of a list. Question 11 Which method is used to return the number of elements in a list? A. len() B. size()

keywords for function definition. Option B (define) is also not a Python keyword. Question 13 What is the error in the following Python code snippet? port = input("Secure Web access? Y/N: ") if port == "Y" print("Use port 443.") else print("Use port 80.") A. Incorrect use of quotation marks B. Missing colons at the end of the if and else lines C. Incorrect indentation D. Missing parentheses in the print statements Correct Answer: B Explanation: In Python, the if, elif, and else statements (as well as for, while, def, and class statements) require a colon at the end of the line to indicate the start of an indented code block. The provided code is missing the colon after if port == "Y" and after else. Option A is incorrect; the quotation marks are fine. Option C is incorrect; the indentation is missing because the colons are missing. Option D is incorrect; the print functions have correct parentheses.

Question 14 What is the output of the following code snippet? print("5" + "3") A. 8 B. 53 C. 15 D. TypeError Correct Answer: B Explanation: In Python, the + operator performs concatenation when used with strings. It joins the two strings together into a new string. In this case, "5" + "3" results in the string "53". Option A (8) would be the result of integer addition (5 + 3). Option C (15) would be the result of multiplication (5 * 3). Option D (TypeError) would occur if you tried to add an integer to a string without explicit conversion. Question 15 What is the result of the following expression? print(3 ** 2) A. 6 B. 9

Option C (swapcase()) swaps the case of all characters, converting uppercase to lowercase and vice versa. Question 17 What will be the output of the following code? x = [1, 2, 3] x.append(4) print(x) A. [1, 2, 3] B. [4, 1, 2, 3] C. [1, 2, 3, 4] D. [1, 2, 3][4] Correct Answer: C Explanation: The append() method adds a single element to the end of a list, modifying it in place. The list x initially contains [1, 2, 3]. After x.append(4), the element 4 is appended to the end, resulting in [1, 2, 3, 4]. Option B would be the result of using insert(0, 4). Option A is the original list before modification. Question 18 Based on the Python code snippet:

def greet(name, greeting = "Welcome to WGU"): return f"{greeting}, {name}!" What is the purpose of the first line of code? A. To define a function with a required parameter name and an optional parameter greeting B. To call the greet function C. To define a function with no parameters D. To import the greet function Correct Answer: A Explanation: The def keyword defines a function. The function is named greet. The parentheses contain the parameters: name is a required positional parameter, and greeting is an optional keyword parameter with a default value of "Welcome to WGU". This line defines the function but does not execute or call it. Options B, C, and D describe different actions. Question 19 Which characteristics are associated with tuples in Python? A. Mutable and unordered B. Ordered and immutable C. Mutable and ordered D. Unordered and immutable

Section 2: Advanced Data Structures and Operations Question 21 What is the output of len("Hello World")? A. 10 B. 11 C. 12 D. 9 Correct Answer: B Explanation: The len() function returns the total number of characters in a string, which includes letters, spaces, and punctuation. The string "Hello World" has 5 characters for "Hello", 1 for the space, and 5 for "World", totaling 11 characters. Question 22 What is the output of bool([])? A. True B. False C. None D. Error

Correct Answer: B Explanation: In Python, an empty list [] is considered a "falsy" value. When evaluated in a Boolean context, like with the bool() function, it returns False. This is consistent with other empty containers, such as empty strings, tuples, and dictionaries. Question 23 What is the index position of the element 40 in the following list? numbers = [10, 20, 30, 40] A. numbers[1] B. numbers[2] C. numbers[3] D. numbers[4] Correct Answer: C Explanation: In Python, list indices are zero-based. The first element is at index 0, the second at index 1, and so on. For the list [10, 20, 30, 40], the element 10 is at index 0, 20 is at index 1, 30 is at index 2, and 40 is at index 3. Question 24

D. 4

Correct Answer: C Explanation: Similar to lists, tuples are zero-indexed. The element at index 0 is 1, index 1 is 2, index 2 is 3, and index 3 is 4. Therefore, my_tuple[2] returns the integer 3. Question 26 Which method is used to add multiple elements from an iterable to the end of a list? A. append() B. insert() C. extend() D. add() Correct Answer: C Explanation: The extend() method is used to add all elements from an iterable (like another list, tuple, or set) to the end of a list. It modifies the list in place. Option A (append()) adds a single element. Option B (insert()) adds an element at a specific position. Option D (add()) is for sets.

Question 27 What is the difference between remove() and discard() methods in a Python set? A. They behave the same. B. remove() raises an error if the item is missing; discard() does not. C. discard() raises an error if the item is missing; remove() does not. D. Both methods raise an error if the item is missing. Correct Answer: B Explanation: The remove() method is used to delete a specific element from a set. If the element is not found, it raises a KeyError. The discard() method performs the same deletion but will not raise an error if the element is not present; it simply does nothing. This makes discard() safer to use when you are not certain the item exists. Question 28 How do you add a single element to a set in Python? A. set.append(item) B. set.insert(item) C. set.add(item) D. set.extend(item)