WGU D335 Final Practice Exam 2026: 300+ Python
Programming Questions with Verified Answers,
Detailed Rationales, and Complete Test Bank for
Introduction to Python OA
SECTION 1: FUNDAMENTALS & DATA TYPES
Question 1
What is the output of the following code?
python
x = [10, 20, 30, 40, 50]
print(x[-2])
A. 20
B. 30
C. 40
D. 50
Correct Answer: C. 40
Rationale: Negative indexing starts from the end of the list. Index -1 is 50, -2 is 40, -
3 is 30, etc. So x[-2] returns the second-to-last element, which is 40 .
Question 2
Which of the following Python types is immutable?
A. List
B. Dictionary
C. Set
D. Tuple
Correct Answer: D. Tuple
,Rationale: Tuples are immutable - once created, their elements cannot be changed,
added, or removed. Lists, dictionaries, and sets are all mutable data structures .
Question 3
What will the following code print?
python
print(3 + 2.5)
A. 5
B. 5.5
C. 6
D. Error (type mismatch)
Correct Answer: B. 5.5
Rationale: Python performs implicit type conversion (type coercion) when mixing
integers and floats. The integer 3 is converted to a float (3.0) before addition,
resulting in a float .
Question 4
What is the output of this code?
python
text = "Python Programming"
print(text[7:])
A. "Python"
B. "Programming"
C. "Python P"
D. "rogramming"
Correct Answer: B. "Programming"
Rationale: String slicing [7:] means start at index 7 and go to the end. Index 7 is the
'P' of "Programming" (remember indexing starts at 0: P=0, y=1, t=2, h=3, o=4, n=5,
space=6, P=7...).
,Question 5
What does the type() function do in Python?
A. Converts a value to a specified type
B. Returns the data type of an object
C. Checks if two objects are the same type
D. Creates a new type
Correct Answer: B. Returns the data type of an object
Rationale: The type() function is used to determine the data type of any object in
Python, such as <class 'int'>, <class 'str'>, etc.
SECTION 2: CONTROL FLOW & FUNCTIONS
Question 6
What will this code print?
python
for i in range(1, 5, 2):
print(i, end=' ')
A. 1 2 3 4
B. 1 3
C. 2 4
D. 1 3 5
Correct Answer: B. 1 3
Rationale: range(1, 5, 2) starts at 1, stops before 5, and steps by 2. This generates:
1, 3. The end=' ' prints them on one line with spaces .
Question 7
What is the output of the following code?
python
def multiply(x, y=2):
return x * y
print(multiply(5))
, print(multiply(5, 3))
A. 10\n15
B. 10\n10
C. 5\n15
D. Error
Correct Answer: A. 10\n15
Rationale: The function has a default parameter y=2. First call uses default (5*2=10),
second call overrides default (5*3=15). The \n represents newline between outputs .
Question 8
Which keyword is used to handle exceptions in Python?
A. catch
B. try/except
C. throw/catch
D. handle
Correct Answer: B. try/except
Rationale: Python uses try/except blocks for exception handling. The code that
might raise an exception goes in the try block, and handling code goes in
the except block .
Question 9
What will this code print?
python
try:
result =
except ZeroDivisionError:
print("Cannot divide by zero")
finally:
print("Operation complete")
A. Cannot divide by zero
B. Operation complete
Programming Questions with Verified Answers,
Detailed Rationales, and Complete Test Bank for
Introduction to Python OA
SECTION 1: FUNDAMENTALS & DATA TYPES
Question 1
What is the output of the following code?
python
x = [10, 20, 30, 40, 50]
print(x[-2])
A. 20
B. 30
C. 40
D. 50
Correct Answer: C. 40
Rationale: Negative indexing starts from the end of the list. Index -1 is 50, -2 is 40, -
3 is 30, etc. So x[-2] returns the second-to-last element, which is 40 .
Question 2
Which of the following Python types is immutable?
A. List
B. Dictionary
C. Set
D. Tuple
Correct Answer: D. Tuple
,Rationale: Tuples are immutable - once created, their elements cannot be changed,
added, or removed. Lists, dictionaries, and sets are all mutable data structures .
Question 3
What will the following code print?
python
print(3 + 2.5)
A. 5
B. 5.5
C. 6
D. Error (type mismatch)
Correct Answer: B. 5.5
Rationale: Python performs implicit type conversion (type coercion) when mixing
integers and floats. The integer 3 is converted to a float (3.0) before addition,
resulting in a float .
Question 4
What is the output of this code?
python
text = "Python Programming"
print(text[7:])
A. "Python"
B. "Programming"
C. "Python P"
D. "rogramming"
Correct Answer: B. "Programming"
Rationale: String slicing [7:] means start at index 7 and go to the end. Index 7 is the
'P' of "Programming" (remember indexing starts at 0: P=0, y=1, t=2, h=3, o=4, n=5,
space=6, P=7...).
,Question 5
What does the type() function do in Python?
A. Converts a value to a specified type
B. Returns the data type of an object
C. Checks if two objects are the same type
D. Creates a new type
Correct Answer: B. Returns the data type of an object
Rationale: The type() function is used to determine the data type of any object in
Python, such as <class 'int'>, <class 'str'>, etc.
SECTION 2: CONTROL FLOW & FUNCTIONS
Question 6
What will this code print?
python
for i in range(1, 5, 2):
print(i, end=' ')
A. 1 2 3 4
B. 1 3
C. 2 4
D. 1 3 5
Correct Answer: B. 1 3
Rationale: range(1, 5, 2) starts at 1, stops before 5, and steps by 2. This generates:
1, 3. The end=' ' prints them on one line with spaces .
Question 7
What is the output of the following code?
python
def multiply(x, y=2):
return x * y
print(multiply(5))
, print(multiply(5, 3))
A. 10\n15
B. 10\n10
C. 5\n15
D. Error
Correct Answer: A. 10\n15
Rationale: The function has a default parameter y=2. First call uses default (5*2=10),
second call overrides default (5*3=15). The \n represents newline between outputs .
Question 8
Which keyword is used to handle exceptions in Python?
A. catch
B. try/except
C. throw/catch
D. handle
Correct Answer: B. try/except
Rationale: Python uses try/except blocks for exception handling. The code that
might raise an exception goes in the try block, and handling code goes in
the except block .
Question 9
What will this code print?
python
try:
result =
except ZeroDivisionError:
print("Cannot divide by zero")
finally:
print("Operation complete")
A. Cannot divide by zero
B. Operation complete