PROGRAMMING IN PYTHON 2026 |
PRACTICE QUESTIONS, VERIFIED ANSWERS
& DETAILED RATIONALES
WGU D335 OA: INTRODUCTION TO PROGRAMMING IN PYTHON 2026 PRACTICE
QUESTIONS, VERIFIED ANSWERS & DETAILED RATIONALES
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
DOCUMENT OVERVIEW
• This comprehensive practice exam contains 200 verified questions with detailed
rationales to help you master Python fundamentals across all core exam topics,
from basic syntax to object-oriented programming concepts.
• Study this material by working through questions systematically, reviewing each
rationale carefully to reinforce understanding—focus on areas where you struggle
most, and revisit those sections before attempting the actual assessment.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
SECTION 1: BASIC SYNTAX AND DATA TYPES (QUESTIONS 1-30)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Question 1: Which of the following is a valid Python variable name?
A) 2var_name
B) var-name
C) var_name
D) var name
E) @var_name
CORRECT ANSWER: C) var_name
Rationale: Python variable names must start with a letter (a-z, A-Z) or an underscore
(_), followed by letters, digits, or underscores. Option C follows this rule exactly.
,Option A is invalid because variable names cannot start with a digit. Option B is
invalid because hyphens are not allowed in variable names. Option D is invalid
because spaces are not permitted. Option E is invalid because special characters
like @ are not allowed.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Question 2: What will be the output of the following code? x = 10; y = 3; print(x
% y)
A) 3
B) 3.33
C) 1
D) 13
E) 0
CORRECT ANSWER: C) 1
Rationale: The modulo operator (%) returns the remainder after division. When 10
is divided by 3, the quotient is 3 with a remainder of 1. Therefore, 10 % 3 equals 1.
This operator is useful for determining if numbers are even or odd, or for cycling
through values.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Question 3: Which data type is used to store a single character or string of
characters?
A) int
B) float
C) str
D) bool
E) char
,CORRECT ANSWER: C) str
Rationale: In Python, the str (string) data type is used to store text data, including
single characters, words, sentences, or any sequence of characters. Python does
not have a separate 'char' data type like some other languages. The int type stores
integers, float stores decimal numbers, and bool stores True/False values.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Question 4: What is the result of the expression: 2 ** 3 + 5?
A) 11
B) 13
C) 40
D) 21
E) 8
CORRECT ANSWER: B) 13
Rationale: The exponentiation operator (**) has higher precedence than addition.
First, 2 ** 3 is calculated, which equals 8 (2 multiplied by itself 3 times). Then, 8 + 5 =
13. Understanding operator precedence is crucial for writing correct expressions in
Python.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Question 5: Which of the following correctly describes the purpose of the
input() function?
A) It prints output to the console
B) It reads a line of text from the user and returns it as a string
C) It creates a new variable
D) It calculates mathematical expressions
E) It terminates the program
, CORRECT ANSWER: B) It reads a line of text from the user and returns it as a
string
Rationale: The input() function is used to receive input from the user through the
keyboard. It always returns the input as a string data type, even if the user enters
numbers. If numeric input is needed, the result must be explicitly converted using
int() or float(). The print() function is used for output, not input.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Question 6: What will be printed by the following code? print(type(5.0))
A) <class 'int'>
B) <class 'float'>
C) <class 'str'>
D) <class 'number'>
E) float
CORRECT ANSWER: B) <class 'float'>
Rationale: The type() function returns the data type of an object. The value 5.0 is a
floating-point number (contains a decimal point), so type(5.0) returns <class 'float'>.
Note that 5 (without decimal) would return <class 'int'>, and the decimal point is
what distinguishes float from int in Python.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Question 7: What is the output of: print("Hello" + " " + "World")?
A) Hello World
B) "Hello World"
C) Hello + World
D) HelloWorld
E) Error: cannot concatenate