




































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





































Ace the WGU E010 Foundations of Programming (Python) OA practice
Exam with practice questions covering Python syntax, data types,
control structures, functions, data structures (lists, tuples,
dictionaries, sets), file I/O, exception handling, modules, and basic
object-oriented programming. This study guide helps reinforce
foundational coding concepts and supports effective preparation for
objective assessments. Designed to improve problem-solving skills
and boost confidence in Python programming. Suitable for computer
science, IT, and programming students.
Multiple choice.
Section 1: Python Fundamentals & Syntax (Questions 1–15)
World!")
Hello, World!
C) print("Hello, World!")
D)An error occurs Answer: A. Hello, World! Explanation: The print() func-
tion outputs the string literal to the console without the quotation
marks. The quotes are used only to denote the string.
E) Which of the following is a valid variable name in Python? A)2_vari-
able B) my-variable C) _myVariable D) my variable Answer: C. _myVari-
able Explanation: Variable names can start with a letter or under-
score, cannot start with a digit, and cannot contain spaces or hy-
phens. Underscore is allowed.
F) In Python, which symbol is used for single-line comments? A) // B) #
C) /* D) Answer: B.
Explanation: type() returns the class of the object. 3.14 is a
floating-point number, so the output indicates a float class.
** C) * D) // Answer: B.** Explanation: ** is the exponentiation opera-
tor (e.g., 2 ** 3 equals 8). The ^ operator is used for bitwise XOR.
turns the integer quotient, discarding the remainder (17 // 5 = 3).
Answer: B. 1
Explanation: % is the modulo operator; it returns the
remainder of division (10 divided by 3 gives remainder 1).
teger? A) int("123") B) integer("123") C) str(123) D) "123".to_int() An-
swer: A. int("123") Explanation: The built-in int() function converts a
string (or other numeric type) to an integer, provided the string repre-
sents a valid integer.
in the string. "Python" has 6 characters: P, y, t, h, o, n.
input("Enter name: ") B)read("Enter name: ")
Section 2: Control Flow (if, elif, else, loops) (Questions 16–30)
e
e
0.0, and complex zero evaluate toFalse in a Boolean context. All non-
zero numbers evaluate to True.
x = 10 if x > 5: print("A") elif x > 7: print("B") else:
print("C")
D)No output Answer: A. A Explanation: The first condition x > 5 is True
(10 > 5), so the block under if executes and prints "A". The elif and else-
blocks are skipped.
E) Which logical operator would be used to check if both conditions a >
5 and b < 10 are True? A) or B) and C) not D) & Answer: B.and Explana-
tion: The and operator returns True only when both operands are
True. This matches the requirement that both conditions must hold.
F) How many times will the following loop execute? python
count = 0 while count < 5: count += 1
Answer: C. break
Explanation: The break statement terminates the innermost
loop (while or for) immediately and resumes execution after
the loop.
python
for i in range(1, 6, 2):
print(i, end=" ")
Answer: B. 1 3 5
Explanation: range(1, 6, 2) starts at 1, goes up to but not in-
cluding 6, with a step of 2. So the values are 1, 3, and 5.
between 10 and 20 (inclusive)?
A) 10 <= n <= 20
B) n >= 10 and n <= 20
C) Both A and B
D) n in range(10,20)
Answer: C. Both A and B
Explanation: Python supports chained comparisons: 10 <= n
<= 20 is equivalent to n >= 10 and n <=
range(10,20) excludes 20, so it's not inclusive of 20.
What is the output of print(not (5 > 3) or (2 == 2))?
Fals
e
e
e
False.(2 == 2) is True. False or True evaluates to True.
B) while loop C) do-whileloop (Python does not have one)
Python has no do-while loop. Both forand while loops check condi-
tions before the first iteration, so they may execute zero times.
x = 5 if x: x = 10
break
print(i, end=" ")
D)No output Answer: A. 0 Explanation: When i = 0, condition false, print
printing 1 or further values.
E) How many times will "Hello"be printed? python i
= 0 while i < 5: print("Hello") i += 2
I) 5 Answer: B. 3 Explanation: i starts 0 → print, i=2; i=2 → print, i=4; i=4 →
print, i=6; now i=6 not <5, stop. Three prints.
65 inclusive? A) age < 18 or age > 65 B) not (18 <= age <= 65)
planation: Both correctly represent the condition. range(18,66) in-
cludes 65, so age not in range(18,66) also works but is less common
for numeric comparisons.
range(2): for j in range(2): print(i*j, end=" ") A)0 0 0 1 B) 0 1 0 1 C) 0 0
0 0 D) 0 1 1 2 Answer: A. 0 0 0 1 Explanation: Outer loop i=0, inner
loop j=0 → 0; j=1 → 0; outer i=1, inner j=0 → 0; j=1 → 1. So output: 0 0 0 1.
python
def add(a, b):
return a + b
result = add(3, 4)
print(result)
add(3,4)
C)Error Answer: A. 7 Explanation: The function takes two parameters
and returns their sum. add(3,4) returns 7, which is assigned to result
and printed.
D)A variable defined inside a function is called a __________ variable.
E) global
F) local
G)static
H)constant Answer: B. local Explanation: Variables declared inside a
function have local scope; they are not accessible outside that func-
tion unless returned or passed.
I) What is the output?
python
x = 10
def change():
x = 20
change()
print(x)
C)None
D)Error Answer: A. 10 Explanation: Inside change(), x = 20creates a local
variable x that shadows the global x. The global x remains un-
changed, soprint(x) outputs 10.
E) How do you make a function return a value without usingreturn?
F) It's impossible; functions without returnreturn None
G)Use yield
H)Use print()
I) Use pass Answer: A. It's impossible; functions without return return-
None Explanation: If no return statement is executed, or a return with
no value, the function returns None implicitly.
tuple. **kwargs collects keyword arguments into a
dictionary.
python def func(x, y=2,
z=3): return x + y + z
print(func(1, z=4))
is overridden to 4. Sum = 1+2+4 = 7.
def multiply(a, b):? A) multiply(2)(3) B) multiply(2, 3) C) multiply(a=2,
b=3)
ing positional arguments (multiply(2,3)) or keyword arguments (multi-
ply(a=2,b=3)).
l
fined inside a function is local to that function. If the function is
nested inside another function, it is local to the inner function and
can be accessed by the inner function (but not by the outer func-
tion).
python def outer(): x = "local" def inner():
nonlocal x x = "nonlocal" inner() print(x)
outer() A) local B) nonlocal