Docsity

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

Toggle sidebar
bg1
1 | P a g e
WGU D522 Python for IT Automation | Task 1 &
Task 2 Newest Exam Preparation With Complete
Questions And Correct Answers With Rationales
Already Graded A+Brand New Version!!
Question 1
Which programming paradigm focuses on describing a sequence of
steps to perform a task?
A) Object-Oriented Programming
B) Functional Programming
C) Imperative/Procedural Programming
D) Declarative Programming
Correct Answer: C
Rationale: Imperative or procedural programming is characterized by a
step-by-step sequence of instructions that change the program's state.
This approach is foundational to scripting and automation, where tasks
are broken down into a series of explicit commands executed in order.
Question 2
What is a key trait of Object-Oriented Programming (OOP)?
A) Emphasizes pure functions and immutable data
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 1 Task 2 Newest Exam and more Exams Nursing in PDF only on Docsity!

WGU D522 Python for IT Automation | Task 1 &

Task 2 Newest Exam Preparation With Complete

Questions And Correct Answers With Rationales

Already Graded A+Brand New Version!!

Question 1 Which programming paradigm focuses on describing a sequence of steps to perform a task? A) Object-Oriented Programming B) Functional Programming C) Imperative/Procedural Programming D) Declarative Programming Correct Answer: C Rationale: Imperative or procedural programming is characterized by a step-by-step sequence of instructions that change the program's state. This approach is foundational to scripting and automation, where tasks are broken down into a series of explicit commands executed in order. Question 2 What is a key trait of Object-Oriented Programming (OOP)? A) Emphasizes pure functions and immutable data

B) Organizes code around objects that encapsulate data and behavior C) Describes what the program should accomplish without specifying how D) Defines a set of logical conditions and lets the system deduce solutions Correct Answer: B Rationale: Object-Oriented Programming models real-world entities as "objects" that contain both data (attributes) and behavior (methods). This encapsulation promotes modularity, reusability, and is particularly effective for complex automation systems where components like network devices or servers can be represented as objects. Question 3 Python is known for being a multi-paradigm language. Which paradigms does Python support? A) Only Procedural Programming B) Only Object-Oriented Programming C) Imperative, Object-Oriented, and Functional D) Only Functional and Declarative Correct Answer: C Rationale: Python is a versatile language that supports multiple programming styles. Developers can write procedural scripts, build complex class hierarchies using OOP, and employ functional

Correct Answer: B Rationale: Unlike many languages that use braces or keywords to delimit code blocks, Python uses indentation (whitespace) to define the structure and hierarchy of code. Consistent indentation is required to indicate which statements belong to loops, conditionals, and function definitions. Question 6 Which of the following is the correct way to create a single-line comment in Python? A) /* comment */ B) # comment C) // comment D) Correct Answer: B Rationale: In Python, the hash character (#) is used to indicate a single- line comment. Everything following the # on that line is ignored by the interpreter. Comments are used for documentation and for temporarily disabling code during debugging. Question 7 What will be the result of the expression 5 + 3 * 2?

A) 16

B) 13

C) 11

D) 10

Correct Answer: C Rationale: Python follows standard operator precedence rules. The multiplication operator (*) has higher precedence than addition (+), so 3 * 2 is evaluated first to yield 6, and then 5 + 6 results in 11. Question 8 What is the result of the expression 3 ** 2? A) 6 B) 8 C) 9 D) 12 Correct Answer: C Rationale: The ** operator in Python performs exponentiation. Thus, 3 ** 2 is equivalent to 3 raised to the power of 2, which equals 9. Question 9 What is the output of print("5" + "3")?

What is the result of bool(0)? A) True B) False C) 0 D) Error Correct Answer: B Rationale: In Python, the integer 0 is considered a "falsey" value. When passed to the bool() constructor, it evaluates to False. Other falsey values include None, empty sequences, and empty strings. Question 12 Which of the following is a mutable data type in Python? A) Tuple B) String C) List D) Integer Correct Answer: C Rationale: Lists are mutable, meaning their contents can be modified after creation. In contrast, tuples and strings are immutable (cannot be changed), and integers are immutable as well.

Question 13 What does len("Hello") return? A) 4 B) 5 C) 6 D) Error Correct Answer: B Rationale: The len() function returns the number of characters in a string. The string "Hello" contains five characters: H, e, l, l, o. Question 14 Which method is used to add an item to the end of a list? A) add() B) insert() C) append() D) push() Correct Answer: C Rationale: The append() method adds a single element to the end of a list. insert() adds at a specific position, and push() is not a list method in Python.

Rationale: The with statement is a context manager that automatically closes the file when the block of code is exited, even if an exception occurs. This prevents resource leaks and ensures proper file handling. Question 17 Which loop in Python is guaranteed to execute at least once? A) for loop B) while loop C) do-while loop D) None of the above Correct Answer: D Rationale: Python does not have a do-while loop. A while loop checks the condition before each iteration, so it may execute zero times. A for loop also may execute zero times if the iterable is empty. Question 18 What is the result of 3 // 2 in Python? A) 1. B) 2 C) 1 D) Error

Correct Answer: C Rationale: The // operator performs floor division, which divides the numbers and rounds down to the nearest integer. 3 divided by 2 is 1.5, and floor division yields 1. Question 19 Which keyword is used to handle exceptions in Python? A) catch B) except C) handle D) error Correct Answer: B Rationale: Python uses the try-except block for exception handling. The except clause catches and handles exceptions that occur in the try block. Other languages may use catch, but Python uses except. Question 20 Which module is used to interact with the operating system for tasks like file permissions or environment variables? A) sys B) math C) os

A) write() B) read() C) append() D) input() Correct Answer: A Rationale: The write() method is used to write string data to a file object. It is appropriate for adding or overwriting content in a file, such as a network configuration file. Question 23 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 call the function B) To define a function with a default greeting parameter C) To assign a variable D) To print a message Correct Answer: B Rationale: The def keyword defines a function. The parameter greeting has a default value of "Welcome to WGU", meaning if no argument is provided for greeting, the default will be used. This allows the function to be called with a custom greeting or without one.

Question 24 This Python code snippet returns a syntax error when run: def multiply_numbers(num1, num2) result = num1 * num2 return result num1 = 5 num2 = 8 print(multiply_numbers(num1, num2)) Which code adjustment will resolve the syntax error? A) Add a colon after def multiply_numbers(num1, num2) B) Remove the return statement C) Change the variable names D) Add parentheses around the parameters Correct Answer: A Rationale: In Python, a colon (:) is required at the end of a function definition line to indicate the start of the function body. The absence of the colon causes a syntax error. Adding the colon resolves the issue. Question 25 Based on the Python snippet: devices = ["router01", "switch01", "modem01", "gateway01", "printer01"] Which data structure is being used to store the names? A) Tuple B) Dictionary C) List

A developer is creating a Python script to capture metrics for different network interfaces on a router, with each set of metrics treated as a single, immutable record. Which data structure should be used? A) List B) Dictionary C) Tuple D) Set Correct Answer: C Rationale: Tuples are immutable, ordered sequences. They are ideal for representing fixed, unchangeable records, such as a snapshot of network metrics at a specific point in time. This ensures the historical data cannot be accidentally modified. Question 28 Based on the Python list: numbers = [10, 20, 30, 40] What is the index position of the element "40"? A) numbers[0] B) numbers[1] C) numbers[2] D) numbers[3] Correct Answer: D

Rationale: Python lists use zero-based indexing. The first element is at index 0, the second at index 1, and so on. The element 40 is the fourth element, so its index is 3. Question 29 Which characteristics are associated with tuples in Python? A) Ordered and changeable B) Unordered and changeable C) Ordered and unchangeable D) Unordered and unchangeable Correct Answer: C Rationale: Tuples are ordered sequences that maintain the order of elements. They are immutable, meaning once created, their elements cannot be changed, added, or removed. This makes them suitable for fixed data. Question 30 What is the error in the following Python code? port = input("Secure Web access? Y/N: ") if port == "Y" print("Use port 443.") else print("Use port 80.") A) Incorrect variable name B) Missing colons at the end of if and else lines C) Missing parentheses

Which Python code snippet correctly creates a dictionary with key- value pairs for network device management? A) devices = ('Router1', '192.168.1.2') B) devices = ['Router1' = '192.168.1.2'] C) devices = {'Router1': '192.168.1.2', 'Switch2': '10.0.0.2'} D) devices = {'Router1', 'Switch2'} Correct Answer: C Rationale: Dictionaries use curly braces {} with keys and values separated by colons. Option C correctly defines a dictionary mapping device names to IP addresses. Option A is a tuple, B uses invalid syntax, and D is a set. Question 33 Which Python collection is best suited for storing an ordered sequence of elements that can be modified? A) Tuple B) Dictionary C) List D) Set Correct Answer: C Rationale: Lists are ordered, mutable sequences. They are ideal for collections that need to maintain order and allow modifications such as

adding, removing, or changing elements. Tuples are immutable, dictionaries are key-value mappings, and sets are unordered. Question 34 Which method is used to return the number of elements in a list? A) count() B) size() C) len() D) length() Correct Answer: C Rationale: The built-in len() function returns the number of items in a container, such as a list, tuple, dictionary, or string. There is no size() or length() method for lists in Python. Question 35 Which of the following is used to declare a function in Python? A) function B) def C) define D) func Correct Answer: B