WGU D335 – Introduction To Programming In Python
Exam | Practice Questions And Answers 2026/2027 |
Complete Questions And Answers (Verified Answers) |
Exam Prep | Comprehensive Exam Guide 2026&2027
1. A Python program needs to store a customer's age so that arithmetic operations can be
performed on it later. Which data type is most appropriate?
A. str
B. int
C. bool
D. list
Answer: B
An int stores whole numbers and is therefore appropriate for an age that will be used in
arithmetic calculations.
2. A developer wants to display the value stored in the variable name to the console. Which
statement should be used?
A. print(name)
B. display = name
C. console(name)
D. output.name()
Answer: A
The built-in print() function writes the value of its argument to standard output.
3. A program receives the text "42" from user input and needs to add 8 to it numerically.
Which operation is required first?
A. str(42)
B. bool("42")
C. int("42")
D. list("42")
Answer: C
input() returns text, so int() converts the numeric string "42" into the integer 42 before
arithmetic is performed.
,4. Which Python expression evaluates to True?
A. 5 < 2
B. 10 == 10
C. 7 != 7
D. 3 > 9
Answer: B
The equality comparison 10 == 10 is true because both operands have the same value.
5. A developer needs to execute a block only when a customer's balance is greater than
zero. Which construct is appropriate?
A. if
B. for
C. import
D. return
Answer: A
An if statement conditionally executes a block when its Boolean condition evaluates to true.
6. What is the value of result after the following code executes? result = 17 // 5
A. 2
B. 3
C. 3.4
D. 4
Answer: B
The // operator performs floor division. Seventeen divided by five is 3 with a remainder of 2,
so the result is 3.
7. A program must repeat an operation exactly 10 times using a known sequence of
iterations. Which approach is most appropriate?
A. if
B. try
C. for
D. except
Answer: C
,A for loop is well suited to iterating a known number of times or iterating over a sequence or
range.
8. Which value is returned by len("Python")?
A. 5
B. 6
C. 7
D. 8
Answer: B
The string "Python" contains six characters, so len() returns 6.
9. A developer wants to access the first element of the list colors = ["red", "blue",
"green"]. Which expression should be used?
A. colors[0]
B. colors[1]
C. colors[-1]
D. colors.first()
Answer: A
Python sequences use zero-based indexing, so index 0 identifies the first element.
10. Which collection is specifically designed to store key-value pairs?
A. Tuple
B. Set
C. Dictionary
D. String
Answer: C
A dictionary stores data as key-value pairs, allowing values to be retrieved through their
associated keys.
11. A program must prevent modification of a collection after it is created. Which built-in
collection type is most appropriate?
A. List
B. Tuple
C. Dictionary
D. Set
, Answer: B
Tuples are immutable sequences, meaning their elements cannot be reassigned after
creation.
12. What does the expression 7 % 3 return?
A. 0
B. 1
C. 2
D. 3
Answer: C
The modulus operator % returns the remainder after division. Seven divided by three leaves a
remainder of two.
13. A developer wants to execute one block when a condition is true and another block
when it is false. Which construct is appropriate?
A. if...else
B. for...in
C. try...finally
D. while...continue
Answer: A
The if...else structure provides two alternative execution paths based on a Boolean condition.
14. Which statement correctly defines a function named calculate_total with no
parameters?
A. function calculate_total():
B. define calculate_total():
C. def calculate_total():
D. func calculate_total():
Answer: C
Python functions are defined with the def keyword followed by the function name and
parameter list.
15. A function must send a calculated value back to the caller. Which keyword should it
use?
Exam | Practice Questions And Answers 2026/2027 |
Complete Questions And Answers (Verified Answers) |
Exam Prep | Comprehensive Exam Guide 2026&2027
1. A Python program needs to store a customer's age so that arithmetic operations can be
performed on it later. Which data type is most appropriate?
A. str
B. int
C. bool
D. list
Answer: B
An int stores whole numbers and is therefore appropriate for an age that will be used in
arithmetic calculations.
2. A developer wants to display the value stored in the variable name to the console. Which
statement should be used?
A. print(name)
B. display = name
C. console(name)
D. output.name()
Answer: A
The built-in print() function writes the value of its argument to standard output.
3. A program receives the text "42" from user input and needs to add 8 to it numerically.
Which operation is required first?
A. str(42)
B. bool("42")
C. int("42")
D. list("42")
Answer: C
input() returns text, so int() converts the numeric string "42" into the integer 42 before
arithmetic is performed.
,4. Which Python expression evaluates to True?
A. 5 < 2
B. 10 == 10
C. 7 != 7
D. 3 > 9
Answer: B
The equality comparison 10 == 10 is true because both operands have the same value.
5. A developer needs to execute a block only when a customer's balance is greater than
zero. Which construct is appropriate?
A. if
B. for
C. import
D. return
Answer: A
An if statement conditionally executes a block when its Boolean condition evaluates to true.
6. What is the value of result after the following code executes? result = 17 // 5
A. 2
B. 3
C. 3.4
D. 4
Answer: B
The // operator performs floor division. Seventeen divided by five is 3 with a remainder of 2,
so the result is 3.
7. A program must repeat an operation exactly 10 times using a known sequence of
iterations. Which approach is most appropriate?
A. if
B. try
C. for
D. except
Answer: C
,A for loop is well suited to iterating a known number of times or iterating over a sequence or
range.
8. Which value is returned by len("Python")?
A. 5
B. 6
C. 7
D. 8
Answer: B
The string "Python" contains six characters, so len() returns 6.
9. A developer wants to access the first element of the list colors = ["red", "blue",
"green"]. Which expression should be used?
A. colors[0]
B. colors[1]
C. colors[-1]
D. colors.first()
Answer: A
Python sequences use zero-based indexing, so index 0 identifies the first element.
10. Which collection is specifically designed to store key-value pairs?
A. Tuple
B. Set
C. Dictionary
D. String
Answer: C
A dictionary stores data as key-value pairs, allowing values to be retrieved through their
associated keys.
11. A program must prevent modification of a collection after it is created. Which built-in
collection type is most appropriate?
A. List
B. Tuple
C. Dictionary
D. Set
, Answer: B
Tuples are immutable sequences, meaning their elements cannot be reassigned after
creation.
12. What does the expression 7 % 3 return?
A. 0
B. 1
C. 2
D. 3
Answer: C
The modulus operator % returns the remainder after division. Seven divided by three leaves a
remainder of two.
13. A developer wants to execute one block when a condition is true and another block
when it is false. Which construct is appropriate?
A. if...else
B. for...in
C. try...finally
D. while...continue
Answer: A
The if...else structure provides two alternative execution paths based on a Boolean condition.
14. Which statement correctly defines a function named calculate_total with no
parameters?
A. function calculate_total():
B. define calculate_total():
C. def calculate_total():
D. func calculate_total():
Answer: C
Python functions are defined with the def keyword followed by the function name and
parameter list.
15. A function must send a calculated value back to the caller. Which keyword should it
use?