WGU D335 Python OA Exam 2026: 400+ Practice
Questions with Verified Solutions, Code Snippets,
Error Types, and Test-Taking Strategies for Objective
Assessment Success
part 1: Fundamentals, Variables, and Data Types
1. What is the data type of the variable x after the following assignment?
x =
A. int
B. float
C. string
D. list
Correct Answer: B. float
Rationale: The division operator (/) in Python always returns a floating-point
number, even if the result is a whole number. Therefore, evaluates to 2.5, which
is a float.
2. What is the purpose of using int(input()) instead of just input()?
A. To prevent syntax errors.
B. To convert the user's input from a string to an integer.
C. To speed up the program's execution.
D. To format the output as a number.
Correct Answer: B. To convert the user's input from a string to an integer.
Rationale: The input() function always returns data as a string. Wrapping it
with int() converts that string into an integer, allowing it to be used in mathematical
operations.
3. Which of the following is a valid variable name in Python?
A. 2nd_place
B. my-var
C. _total
D. global
Correct Answer: C. _total
Rationale: Variable names must start with a letter or an underscore. They cannot
,start with a number (A) or contain hyphens (B). global is a reserved keyword in
Python and cannot be used as a variable name (D).
4. Which of the following is NOT a Python data type?
A. int
B. string
C. character
D. float
Correct Answer: C. character
Rationale: Unlike languages such as C or Java, Python does not have a dedicated
"character" data type. A single character is simply a string of length 1.
5. What will the following code output?
x = "10"
y = "20"
print(x + y)
A. 30
B. 1020
C. TypeError
D. 10 20
Correct Answer: B. 1020
Rationale: The + operator acts as a concatenation operator when used with strings.
Since both x and y are strings, they are joined together to form "1020".
Part 2: Control Flow and Operators
6. What is the output of the following code?
print(3 + 4 * 2)
A. 14
B. 11
C. 24
D. Error
Correct Answer: B. 11
Rationale: According to Python's operator precedence, multiplication (*) has a
higher precedence than addition (+). Therefore, 4 * 2 is evaluated first (8), and then 3
+ 8 results in 11.
7. Which operator is used for integer (floor) division in Python?
A. /
B. //
C. %
D. \
,Correct Answer: B. //
Rationale: The // operator performs floor division, which divides two numbers and
rounds the result down to the nearest integer. For example, 7 // 2 evaluates to 3.
8. What is a correct way to get the remainder when dividing 17 by 5?
A.
B. 17 // 5
C. 17 % 5
D. 17 ÷ 5
Correct Answer: C. 17 % 5
Rationale: The modulus operator % returns the remainder of a division. 17 divided by
5 is 3 with a remainder of 2.
9. Which loop is guaranteed to execute at least once?
A. A for loop
B. A while loop with a condition that is initially True
C. A while loop with a condition that is initially False
D. No loop structure in Python guarantees at least one execution.
Correct Answer: D. No loop structure in Python guarantees at least one
execution.
Rationale: Python does not have a built-in "do-while" loop. Both for and while loops
check their condition at the beginning (entry-condition loops). If the condition for
a while loop is False at the start, the code block will not execute.
Part 3: Strings and Lists
10. What will be the output of the following code?
text = "Python Programming"
print(text[7:])
A. Python
B. Programming
C. hon Progr
D. Programm
Correct Answer: B. Programming
Rationale: Slicing a string with [7:] means "start at index 7 and go to the end." Index
7 in the string "Python Programming" is the character 'P' of "Programming", so the
output is "Programming".
11. What is the output of the following code?
my_list = [1, 2, 3, 4, 5]
print(my_list[-1])
A. 1
B. 2
, C. 4
D. 5
Correct Answer: D. 5
Rationale: Negative indexing accesses elements from the end of a list. An index of -
1 always refers to the last element.
12. What is the output of the following code?
x = [1, 2, 3, 4, 5]
print(x[1:4])
A. [1, 2, 3]
B. [2, 3, 4]
C. [1, 2, 3, 4]
D. [2, 3, 4, 5]
Correct Answer: B. [2, 3, 4]
Rationale: Python list slicing x[start:stop] includes the element at index start up to
but NOT including the element at index stop. So x[1:4] yields indices 1, 2, and 3,
which correspond to the values 2, 3, and 4.
13. Which slicing operation extracts the last three characters of a string s?
A. s[3:]
B. s[:3]
C. s[-3:]
D. s[:-3]
Correct Answer: C. s[-3:]
Rationale: Negative indexing in Python counts from the end of the string. s[-
3:] starts at the third-to-last character and goes to the end, extracting the last three
characters.
Part 4: Functions, Modules, and Error Handling
14. Which of the following correctly defines a function in Python that returns
the square of a number?
A. function square(n): return n * n
B. def square(n): return n ** 2
C. def square(n) { return n * n; }
D. define square(n): return n ^ 2
Correct Answer: B. def square(n): return n ** 2
Rationale: Python uses the def keyword to define functions. The exponentiation
operator is **. The caret ^ is bitwise XOR, not exponentiation.
15. Which statement correctly imports a module named pigAge?
A. import pigage
Questions with Verified Solutions, Code Snippets,
Error Types, and Test-Taking Strategies for Objective
Assessment Success
part 1: Fundamentals, Variables, and Data Types
1. What is the data type of the variable x after the following assignment?
x =
A. int
B. float
C. string
D. list
Correct Answer: B. float
Rationale: The division operator (/) in Python always returns a floating-point
number, even if the result is a whole number. Therefore, evaluates to 2.5, which
is a float.
2. What is the purpose of using int(input()) instead of just input()?
A. To prevent syntax errors.
B. To convert the user's input from a string to an integer.
C. To speed up the program's execution.
D. To format the output as a number.
Correct Answer: B. To convert the user's input from a string to an integer.
Rationale: The input() function always returns data as a string. Wrapping it
with int() converts that string into an integer, allowing it to be used in mathematical
operations.
3. Which of the following is a valid variable name in Python?
A. 2nd_place
B. my-var
C. _total
D. global
Correct Answer: C. _total
Rationale: Variable names must start with a letter or an underscore. They cannot
,start with a number (A) or contain hyphens (B). global is a reserved keyword in
Python and cannot be used as a variable name (D).
4. Which of the following is NOT a Python data type?
A. int
B. string
C. character
D. float
Correct Answer: C. character
Rationale: Unlike languages such as C or Java, Python does not have a dedicated
"character" data type. A single character is simply a string of length 1.
5. What will the following code output?
x = "10"
y = "20"
print(x + y)
A. 30
B. 1020
C. TypeError
D. 10 20
Correct Answer: B. 1020
Rationale: The + operator acts as a concatenation operator when used with strings.
Since both x and y are strings, they are joined together to form "1020".
Part 2: Control Flow and Operators
6. What is the output of the following code?
print(3 + 4 * 2)
A. 14
B. 11
C. 24
D. Error
Correct Answer: B. 11
Rationale: According to Python's operator precedence, multiplication (*) has a
higher precedence than addition (+). Therefore, 4 * 2 is evaluated first (8), and then 3
+ 8 results in 11.
7. Which operator is used for integer (floor) division in Python?
A. /
B. //
C. %
D. \
,Correct Answer: B. //
Rationale: The // operator performs floor division, which divides two numbers and
rounds the result down to the nearest integer. For example, 7 // 2 evaluates to 3.
8. What is a correct way to get the remainder when dividing 17 by 5?
A.
B. 17 // 5
C. 17 % 5
D. 17 ÷ 5
Correct Answer: C. 17 % 5
Rationale: The modulus operator % returns the remainder of a division. 17 divided by
5 is 3 with a remainder of 2.
9. Which loop is guaranteed to execute at least once?
A. A for loop
B. A while loop with a condition that is initially True
C. A while loop with a condition that is initially False
D. No loop structure in Python guarantees at least one execution.
Correct Answer: D. No loop structure in Python guarantees at least one
execution.
Rationale: Python does not have a built-in "do-while" loop. Both for and while loops
check their condition at the beginning (entry-condition loops). If the condition for
a while loop is False at the start, the code block will not execute.
Part 3: Strings and Lists
10. What will be the output of the following code?
text = "Python Programming"
print(text[7:])
A. Python
B. Programming
C. hon Progr
D. Programm
Correct Answer: B. Programming
Rationale: Slicing a string with [7:] means "start at index 7 and go to the end." Index
7 in the string "Python Programming" is the character 'P' of "Programming", so the
output is "Programming".
11. What is the output of the following code?
my_list = [1, 2, 3, 4, 5]
print(my_list[-1])
A. 1
B. 2
, C. 4
D. 5
Correct Answer: D. 5
Rationale: Negative indexing accesses elements from the end of a list. An index of -
1 always refers to the last element.
12. What is the output of the following code?
x = [1, 2, 3, 4, 5]
print(x[1:4])
A. [1, 2, 3]
B. [2, 3, 4]
C. [1, 2, 3, 4]
D. [2, 3, 4, 5]
Correct Answer: B. [2, 3, 4]
Rationale: Python list slicing x[start:stop] includes the element at index start up to
but NOT including the element at index stop. So x[1:4] yields indices 1, 2, and 3,
which correspond to the values 2, 3, and 4.
13. Which slicing operation extracts the last three characters of a string s?
A. s[3:]
B. s[:3]
C. s[-3:]
D. s[:-3]
Correct Answer: C. s[-3:]
Rationale: Negative indexing in Python counts from the end of the string. s[-
3:] starts at the third-to-last character and goes to the end, extracting the last three
characters.
Part 4: Functions, Modules, and Error Handling
14. Which of the following correctly defines a function in Python that returns
the square of a number?
A. function square(n): return n * n
B. def square(n): return n ** 2
C. def square(n) { return n * n; }
D. define square(n): return n ^ 2
Correct Answer: B. def square(n): return n ** 2
Rationale: Python uses the def keyword to define functions. The exponentiation
operator is **. The caret ^ is bitwise XOR, not exponentiation.
15. Which statement correctly imports a module named pigAge?
A. import pigage