WGU E010 (D335) FOUNDATIONS OF PROGRAMMING (PYTHON)
FINAL EXAM QUESTIONS WITH DETAILED- VERIFIED ANSWERS-
ALREADY GRADED A+ || NEWEST EXAM 2025-2026
Computer Science / Information Technology
This WGU E010 (D335) Foundations of Programming (Python) exam
covers variables, data types, type conversion, operators (arithmetic,
comparison, logical, assignment), strings (slicing, methods, formatting),
lists, tuples, dictionaries, sets (mutability, operations), conditionals
(if/elif/else, ternary), loops (for, while, break, continue, else), functions
(definition, parameters, return, scope, lambda, recursion), file I/O (open,
read, write, append, with context), exception handling
(try/except/else/finally, raise), and modules (import, math, random, os,
sys).
SECTION 1 – VARIABLES, DATA TYPES, AND OPERATORS (Q1–25)
1. A student writes the following code to calculate the total price of
items, but the output is not as expected. The price per item is $12.50,
and the quantity is 4. The code is:
python
price = "12.50"
quantity = 4
total = price * quantity
print(total)
What is printed, and what is the error?
, Page 2 of 156
A) 50.0 – the code works correctly because strings convert automatically.
B) "12.5012.5012.5012.50" – the string is repeated four times instead of
numeric multiplication.
C) 12.50 * 4 – the expression is printed literally.
D) Error – you cannot multiply a string by an integer.
CORRECT ANSWER: B
Rationale: Multiplying a string by an integer repeats the string. Since
price is a string ("12.50"), not a float, the result is the string repeated four
times. To fix, convert to float: float(price) * quantity.
2. A programmer needs to swap the values of two variables a and b.
Which of the following code snippets correctly swaps them without
using a temporary variable?
A)
python
a=b
b=a
B)
python
, Page 3 of 156
a, b = b, a
C)
python
a=a+b
b=a-b
a=a-b
D) Both B and C are correct in Python.
CORRECT ANSWER: D
Rationale: Python's tuple unpacking (a, b = b, a) is the standard way.
Arithmetic method also works for numbers but fails for strings or if
overflow occurs. Both B and C produce a correct swap.
3. What is the output of the following code?
python
x=7%3
y = 7 // 3
print(x, y)
A) 1 2
B) 2 1
C) 1 2.333
, Page 4 of 156
D) 2.333 2
CORRECT ANSWER: A
Rationale: % gives remainder: 7 ÷ 3 = 2 remainder 1 → x = 1. // gives floor
division: 7 // 3 = 2. Output is 1 2.
4. A student is asked to write an expression that returns True if a number
stored in variable n is within the range 10 to 20 inclusive. Which
expression is correct?
A) 10 <= n <= 20
B) 10 <= n and n <= 20
C) n >= 10 and n <= 20
D) All of the above.
CORRECT ANSWER: D
Rationale: Python supports chained comparisons. All three expressions
evaluate the same way and return True if n is between 10 and 20
inclusive.
5. Consider the code:
python