WGU E010 Foundations of Programming (Python) OA
Final Exam | Complete Exam with Actual Questions &
Correct Verified ANSWERs (Rationales Included) | Latest
Update 2026/2027 – Already Graded A+
Question 1
What is the output of the following code? print(3 + 2 * 4)
A. 24
B. 11
C. 20
D. 14
ANSWER: B
Rationale for Option A: Incorrect. This ANSWER would result from evaluating left to right without
considering operator precedence: (3 + 2) * 4 = 5 * 4 = 20, not 24. This shows a fundamental
misunderstanding of both operator precedence and arithmetic.
Rationale for Option B: Correct. Python follows standard mathematical operator precedence where
multiplication is performed before addition. First, 2 * 4 = 8, then 3 + 8 = 11. This demonstrates
understanding of PEMDAS/BODMAS rules in Python.
Rationale for Option C: Incorrect. This would be the result if you added first then multiplied: (3 + 2) * 4 =
20. However, multiplication has higher precedence than addition in Python, so this is not how the
expression is evaluated.
Rationale for Option D: Incorrect. This ANSWER doesn't correspond to any logical evaluation of the
expression. It might result from adding all numbers (3 + 2 + 4 = 9) or some other miscalculation, showing
confusion about operator precedence.
Question 2
What is the correct way to output the string "Hello, World!" in Python?
A. echo "Hello, World!"
B. printf("Hello, World!")
,C. print("Hello, World!")
D. console.log("Hello, World!")
ANSWER: C
Rationale for Option A: Incorrect. The echo command is used in shell scripting languages like Bash or
batch files, not in Python. Python has its own built-in functions for output and does not use shell
commands directly.
Rationale for Option B: Incorrect. The printf() function is used in C, C++, Java, and similar languages for
formatted output. While Python has a printf-style formatting capability, the function itself is not called
printf() in Python.
Rationale for Option C: Correct. In Python, the built-in print() function is used to output text to the
console. This is the standard and correct way to display output in Python 3.x. The print() function can
take strings, variables, and other data types as arguments.
Rationale for Option D: Incorrect. The console.log() method is used in JavaScript for outputting to the
browser console or Node.js console. This is not valid Python syntax and would result in a NameError if
used in Python.
Question 3
What is the output of the following code? print(5 == 5)
A. True
B. 10
C. False
D. 5
ANSWER: A
Rationale for Option A: Correct. The == operator is a comparison operator that checks if two values are
equal. Since 5 equals 5, the expression evaluates to the Boolean value True. In Python, comparison
operators return Boolean values (True or False).
Rationale for Option B: Incorrect. This would be the result of addition (5 + 5 = 10), not comparison. The
== operator does not perform arithmetic operations; it only compares values and returns a Boolean
result.
Rationale for Option C: Incorrect. False would be the result if the values were not equal (e.g., 5 == 6).
Since 5 does equal 5, the comparison returns True, not False.
Rationale for Option D: Incorrect. The comparison operator does not return one of the compared values.
It returns a Boolean value indicating whether the comparison is true or false. To get 5 as output, you
would simply print(5).
Question 4
,Which of the following is a valid variable name in Python?
A. 2nd_variable
B. my-variable
C. _private_var
D. class
ANSWER: C
Rationale for Option A: Incorrect. Variable names in Python cannot start with a digit. While they can
contain digits, the first character must be a letter or underscore. Starting with "2" makes this an invalid
variable name that would cause a SyntaxError.
Rationale for Option B: Incorrect. Variable names cannot contain hyphens (-) because the hyphen is
interpreted as the subtraction operator in Python. This would cause a SyntaxError. Use underscores (_)
instead to separate words in variable names.
Rationale for Option C: Correct. Variable names can start with an underscore, and _private_var follows
all Python naming conventions. By convention, a leading underscore indicates that a variable is intended
for internal use (private), though Python doesn't enforce true privacy.
Rationale for Option D: Incorrect. While "class" might seem like a valid name, it is actually a reserved
keyword in Python used to define classes. Using reserved keywords as variable names will result in a
SyntaxError. Python has many reserved keywords that cannot be used as identifiers.
Question 5
What data type is the value 3.14 in Python?
A. int
B. str
C. float
D. decimal
ANSWER: C
Rationale for Option A: Incorrect. The int (integer) data type is used for whole numbers without decimal
points, such as 3, -5, or 100. Since 3.14 contains a decimal point, it cannot be an integer.
Rationale for Option B: Incorrect. The str (string) data type is used for text values enclosed in quotes,
such as "3.14" or 'hello'. Without quotes, 3.14 is treated as a numeric value, not a string.
Rationale for Option C: Correct. The float (floating-point number) data type is used for numbers with
decimal points in Python. The value 3.14 is automatically interpreted as a float because it contains a
decimal point. Floats are used for representing real numbers.
, Rationale for Option D: Incorrect. While Python does have a Decimal type in the decimal module for
precise decimal arithmetic, the literal 3.14 without any special import or conversion is a float, not a
Decimal. Decimal must be explicitly imported and used.
Question 6
What is the output of the following code? print(type([]))
A. <class 'tuple'>
B. <class 'list'>
C. <class 'dict'>
D. <class 'set'>
ANSWER: B
Rationale for Option A: Incorrect. A tuple in Python is created using parentheses (), not square brackets.
An empty tuple would be written as () or tuple(). The square brackets indicate a different data structure.
Rationale for Option B: Correct. Square brackets [] create an empty list in Python. The type() function
returns the data type of an object, and for an empty list, it returns <class 'list'>. Lists are mutable,
ordered collections in Python.
Rationale for Option C: Incorrect. A dictionary (dict) in Python is created using curly braces {} with key-
value pairs, such as {} or {'key': 'value'}. Empty curly braces {} actually create an empty dictionary, not a
list.
Rationale for Option D: Incorrect. A set in Python is created using curly braces {} with values (not key-
value pairs) or using the set() function. An empty set must be created with set(), not {}, because {}
creates an empty dictionary.
Question 7
Which operator is used to check if two values are NOT equal in Python?
A. <>
B. !=
C. =!
D. !==
ANSWER: B
Rationale for Option A: Incorrect. The <> operator was used in Python 2 to check for inequality, but it
was removed in Python 3. Using <> in Python 3 will result in a SyntaxError. Modern Python code should
always use != instead.
Final Exam | Complete Exam with Actual Questions &
Correct Verified ANSWERs (Rationales Included) | Latest
Update 2026/2027 – Already Graded A+
Question 1
What is the output of the following code? print(3 + 2 * 4)
A. 24
B. 11
C. 20
D. 14
ANSWER: B
Rationale for Option A: Incorrect. This ANSWER would result from evaluating left to right without
considering operator precedence: (3 + 2) * 4 = 5 * 4 = 20, not 24. This shows a fundamental
misunderstanding of both operator precedence and arithmetic.
Rationale for Option B: Correct. Python follows standard mathematical operator precedence where
multiplication is performed before addition. First, 2 * 4 = 8, then 3 + 8 = 11. This demonstrates
understanding of PEMDAS/BODMAS rules in Python.
Rationale for Option C: Incorrect. This would be the result if you added first then multiplied: (3 + 2) * 4 =
20. However, multiplication has higher precedence than addition in Python, so this is not how the
expression is evaluated.
Rationale for Option D: Incorrect. This ANSWER doesn't correspond to any logical evaluation of the
expression. It might result from adding all numbers (3 + 2 + 4 = 9) or some other miscalculation, showing
confusion about operator precedence.
Question 2
What is the correct way to output the string "Hello, World!" in Python?
A. echo "Hello, World!"
B. printf("Hello, World!")
,C. print("Hello, World!")
D. console.log("Hello, World!")
ANSWER: C
Rationale for Option A: Incorrect. The echo command is used in shell scripting languages like Bash or
batch files, not in Python. Python has its own built-in functions for output and does not use shell
commands directly.
Rationale for Option B: Incorrect. The printf() function is used in C, C++, Java, and similar languages for
formatted output. While Python has a printf-style formatting capability, the function itself is not called
printf() in Python.
Rationale for Option C: Correct. In Python, the built-in print() function is used to output text to the
console. This is the standard and correct way to display output in Python 3.x. The print() function can
take strings, variables, and other data types as arguments.
Rationale for Option D: Incorrect. The console.log() method is used in JavaScript for outputting to the
browser console or Node.js console. This is not valid Python syntax and would result in a NameError if
used in Python.
Question 3
What is the output of the following code? print(5 == 5)
A. True
B. 10
C. False
D. 5
ANSWER: A
Rationale for Option A: Correct. The == operator is a comparison operator that checks if two values are
equal. Since 5 equals 5, the expression evaluates to the Boolean value True. In Python, comparison
operators return Boolean values (True or False).
Rationale for Option B: Incorrect. This would be the result of addition (5 + 5 = 10), not comparison. The
== operator does not perform arithmetic operations; it only compares values and returns a Boolean
result.
Rationale for Option C: Incorrect. False would be the result if the values were not equal (e.g., 5 == 6).
Since 5 does equal 5, the comparison returns True, not False.
Rationale for Option D: Incorrect. The comparison operator does not return one of the compared values.
It returns a Boolean value indicating whether the comparison is true or false. To get 5 as output, you
would simply print(5).
Question 4
,Which of the following is a valid variable name in Python?
A. 2nd_variable
B. my-variable
C. _private_var
D. class
ANSWER: C
Rationale for Option A: Incorrect. Variable names in Python cannot start with a digit. While they can
contain digits, the first character must be a letter or underscore. Starting with "2" makes this an invalid
variable name that would cause a SyntaxError.
Rationale for Option B: Incorrect. Variable names cannot contain hyphens (-) because the hyphen is
interpreted as the subtraction operator in Python. This would cause a SyntaxError. Use underscores (_)
instead to separate words in variable names.
Rationale for Option C: Correct. Variable names can start with an underscore, and _private_var follows
all Python naming conventions. By convention, a leading underscore indicates that a variable is intended
for internal use (private), though Python doesn't enforce true privacy.
Rationale for Option D: Incorrect. While "class" might seem like a valid name, it is actually a reserved
keyword in Python used to define classes. Using reserved keywords as variable names will result in a
SyntaxError. Python has many reserved keywords that cannot be used as identifiers.
Question 5
What data type is the value 3.14 in Python?
A. int
B. str
C. float
D. decimal
ANSWER: C
Rationale for Option A: Incorrect. The int (integer) data type is used for whole numbers without decimal
points, such as 3, -5, or 100. Since 3.14 contains a decimal point, it cannot be an integer.
Rationale for Option B: Incorrect. The str (string) data type is used for text values enclosed in quotes,
such as "3.14" or 'hello'. Without quotes, 3.14 is treated as a numeric value, not a string.
Rationale for Option C: Correct. The float (floating-point number) data type is used for numbers with
decimal points in Python. The value 3.14 is automatically interpreted as a float because it contains a
decimal point. Floats are used for representing real numbers.
, Rationale for Option D: Incorrect. While Python does have a Decimal type in the decimal module for
precise decimal arithmetic, the literal 3.14 without any special import or conversion is a float, not a
Decimal. Decimal must be explicitly imported and used.
Question 6
What is the output of the following code? print(type([]))
A. <class 'tuple'>
B. <class 'list'>
C. <class 'dict'>
D. <class 'set'>
ANSWER: B
Rationale for Option A: Incorrect. A tuple in Python is created using parentheses (), not square brackets.
An empty tuple would be written as () or tuple(). The square brackets indicate a different data structure.
Rationale for Option B: Correct. Square brackets [] create an empty list in Python. The type() function
returns the data type of an object, and for an empty list, it returns <class 'list'>. Lists are mutable,
ordered collections in Python.
Rationale for Option C: Incorrect. A dictionary (dict) in Python is created using curly braces {} with key-
value pairs, such as {} or {'key': 'value'}. Empty curly braces {} actually create an empty dictionary, not a
list.
Rationale for Option D: Incorrect. A set in Python is created using curly braces {} with values (not key-
value pairs) or using the set() function. An empty set must be created with set(), not {}, because {}
creates an empty dictionary.
Question 7
Which operator is used to check if two values are NOT equal in Python?
A. <>
B. !=
C. =!
D. !==
ANSWER: B
Rationale for Option A: Incorrect. The <> operator was used in Python 2 to check for inequality, but it
was removed in Python 3. Using <> in Python 3 will result in a SyntaxError. Modern Python code should
always use != instead.