[WGU D522 PYTHON FOR IT AUTOMATION (SKO1)
EXAM] – QUESTIONS AND ANSWERS | VERIFIED
AND WELL DETAILED ANSWERS | PLUS
RATIONALES | GUARANTEED PASS | LATEST EXAM
UPDATE | STUVIA VERIFIED | EXAM PREP | STUDY
GUIDE | PRACTICE TEST
1. Which Python keyword is used to define a function?
A. define
B. function
C. def
D. func
Correct Answer: C. def
Rationale:
The keyword "def" is used in Python to declare a function definition and create reusable blocks
of code.
2. A system administrator wants to store multiple server names in a single variable. Which
data type is most appropriate?
A. Integer
B. List
C. Float
D. Boolean
Correct Answer: B. List
Rationale:
A list allows multiple values to be stored in a single variable and supports indexing and iteration.
3. Which operator is used to compare equality in Python?
A. =
B. !=
C. ==
D. >=
,Correct Answer: C. ==
Rationale:
The double equals operator checks whether two values are equal, while a single equals sign
assigns a value.
4. Which file mode allows both reading and writing without deleting existing content?
A. r+
B. w
C. a
D. x
Correct Answer: A. r+
Rationale:
The r+ mode opens a file for reading and writing while preserving existing file contents.
5. What is the output type of the input() function in Python?
A. Integer
B. String
C. Boolean
D. Float
Correct Answer: B. String
Rationale:
The input() function always returns user input as a string unless explicitly converted.
6. Which loop is best suited for iterating through items in a list?
A. switch
B. repeat
C. while
D. for
Correct Answer: D. for
Rationale:
The for loop is commonly used for iterating through collections such as lists and tuples.
7. A script crashes due to invalid user input. Which statement should be used to handle the
error gracefully?
A. break
B. try
, C. continue
D. pass
Correct Answer: B. try
Rationale:
The try statement allows exceptions to be handled without terminating the program
unexpectedly.
8. Which module is commonly used to work with operating system functions in Python?
A. random
B. math
C. os
D. csv
Correct Answer: C. os
Rationale:
The os module provides tools for interacting with files, directories, and operating system
functions.
9. Which command installs a Python package from the command line?
A. python install
B. pip install
C. get package
D. py add
Correct Answer: B. pip install
Rationale:
The pip install command downloads and installs Python packages from package repositories.
10. What is the purpose of comments in Python code?
A. Encrypt code
B. Speed execution
C. Improve readability
D. Prevent imports
Correct Answer: C. Improve readability
Rationale:
Comments explain code functionality and improve maintainability for developers and
administrators.
, 11. Which symbol begins a single-line comment in Python?
A. //
B. #
C. <!--
D. **
Correct Answer: B. #
Rationale:
Python uses the hash symbol to create comments ignored during execution.
12. Which function converts a string into an integer?
A. str()
B. float()
C. bool()
D. int()
Correct Answer: D. int()
Rationale:
The int() function converts compatible string values into integers.
13. A network automation script repeatedly checks device status until connectivity is
restored. Which loop is most suitable?
A. for
B. foreach
C. while
D. switch
Correct Answer: C. while
Rationale:
The while loop continues executing as long as a specified condition remains true.
14. Which statement exits a loop immediately?
A. continue
B. skip
C. stop
D. break
Correct Answer: D. break
Rationale:
The break statement terminates loop execution immediately when triggered.
EXAM] – QUESTIONS AND ANSWERS | VERIFIED
AND WELL DETAILED ANSWERS | PLUS
RATIONALES | GUARANTEED PASS | LATEST EXAM
UPDATE | STUVIA VERIFIED | EXAM PREP | STUDY
GUIDE | PRACTICE TEST
1. Which Python keyword is used to define a function?
A. define
B. function
C. def
D. func
Correct Answer: C. def
Rationale:
The keyword "def" is used in Python to declare a function definition and create reusable blocks
of code.
2. A system administrator wants to store multiple server names in a single variable. Which
data type is most appropriate?
A. Integer
B. List
C. Float
D. Boolean
Correct Answer: B. List
Rationale:
A list allows multiple values to be stored in a single variable and supports indexing and iteration.
3. Which operator is used to compare equality in Python?
A. =
B. !=
C. ==
D. >=
,Correct Answer: C. ==
Rationale:
The double equals operator checks whether two values are equal, while a single equals sign
assigns a value.
4. Which file mode allows both reading and writing without deleting existing content?
A. r+
B. w
C. a
D. x
Correct Answer: A. r+
Rationale:
The r+ mode opens a file for reading and writing while preserving existing file contents.
5. What is the output type of the input() function in Python?
A. Integer
B. String
C. Boolean
D. Float
Correct Answer: B. String
Rationale:
The input() function always returns user input as a string unless explicitly converted.
6. Which loop is best suited for iterating through items in a list?
A. switch
B. repeat
C. while
D. for
Correct Answer: D. for
Rationale:
The for loop is commonly used for iterating through collections such as lists and tuples.
7. A script crashes due to invalid user input. Which statement should be used to handle the
error gracefully?
A. break
B. try
, C. continue
D. pass
Correct Answer: B. try
Rationale:
The try statement allows exceptions to be handled without terminating the program
unexpectedly.
8. Which module is commonly used to work with operating system functions in Python?
A. random
B. math
C. os
D. csv
Correct Answer: C. os
Rationale:
The os module provides tools for interacting with files, directories, and operating system
functions.
9. Which command installs a Python package from the command line?
A. python install
B. pip install
C. get package
D. py add
Correct Answer: B. pip install
Rationale:
The pip install command downloads and installs Python packages from package repositories.
10. What is the purpose of comments in Python code?
A. Encrypt code
B. Speed execution
C. Improve readability
D. Prevent imports
Correct Answer: C. Improve readability
Rationale:
Comments explain code functionality and improve maintainability for developers and
administrators.
, 11. Which symbol begins a single-line comment in Python?
A. //
B. #
C. <!--
D. **
Correct Answer: B. #
Rationale:
Python uses the hash symbol to create comments ignored during execution.
12. Which function converts a string into an integer?
A. str()
B. float()
C. bool()
D. int()
Correct Answer: D. int()
Rationale:
The int() function converts compatible string values into integers.
13. A network automation script repeatedly checks device status until connectivity is
restored. Which loop is most suitable?
A. for
B. foreach
C. while
D. switch
Correct Answer: C. while
Rationale:
The while loop continues executing as long as a specified condition remains true.
14. Which statement exits a loop immediately?
A. continue
B. skip
C. stop
D. break
Correct Answer: D. break
Rationale:
The break statement terminates loop execution immediately when triggered.