Docsity

WGU E010 FOUNDATIONS OF PROGRAMMING (PYTHON) OA 2026 PRACTICE EXAM COMPLETE (100) CURRENT, Exams of Semantics of Programming Languages

Toggle sidebar
bg1
Page 1 of 44
WGU E010 FOUNDATIONS OF
PROGRAMMING (PYTHON) OA 2026
PRACTICE EXAM COMPLETE (100) CURRENT
TESTING QUESTIONS AND CORRECT
ANSWERS WITH DETAILED
EXPLANATIONS|GUARANTEED PASS.
PYTHON
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)
1. What is the correct output of the following Python code? print("Hello,
World!")
2. Hello, World! B)
Hello, World!
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c

Partial preview of the text

Download WGU E010 FOUNDATIONS OF PROGRAMMING (PYTHON) OA 2026 PRACTICE EXAM COMPLETE (100) CURRENT and more Exams Semantics of Programming Languages in PDF only on Docsity!

WGU E010 FOUNDATIONS OF

PROGRAMMING (PYTHON) OA 2026

PRACTICE EXAM COMPLETE (100) CURRENT

TESTING QUESTIONS AND CORRECT

ANSWERS WITH DETAILED

EXPLANATIONS|GUARANTEED PASS.

PYTHON

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)

  1. What is the correct output of the following Python code? print("Hello,

World!")

  1. Hello, World! B)

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.

  1. Which operator is used for exponentiation (power) in Python? A)^ B)

** C) * D) // Answer: B.** Explanation: ** is the exponentiation opera-

tor (e.g., 2 ** 3 equals 8). The ^ operator is used for bitwise XOR.

  1. What is the result of 17 // 5 in Python?
  1. 3.0 Answer: B. 3 Explanation: // is the floor division operator; it re-

turns the integer quotient, discarding the remainder (17 // 5 = 3).

  1. What is the output of print(10 % 3)?

Answer: B. 1

Explanation: % is the modulo operator; it returns the

remainder of division (10 divided by 3 gives remainder 1).

  1. Which of the following correctly converts the string "123" to an in-

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.

  1. What is the value of len("Python")?
  1. 4 Answer: B. 6 Explanation: len() returns the number of characters

in the string. "Python" has 6 characters: P, y, t, h, o, n.

  1. Which statement reads input from the user as a string? A)

input("Enter name: ") B)read("Enter name: ")

Section 2: Control Flow (if, elif, else, loops) (Questions 16–30)

  1. What does bool(0) return?
  2. Tru

e

  1. Fals

e

  1. 0
  2. None Answer: B. False Explanation: In Python, numeric values: 0,

0.0, and complex zero evaluate toFalse in a Boolean context. All non-

zero numbers evaluate to True.

  1. What is the output of the following code? python

x = 10 if x > 5: print("A") elif x > 7: print("B") else:

print("C")

17. A

18. B

C)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

G) 4

H) 5

Answer: C. break

Explanation: The break statement terminates the innermost

loop (while or for) immediately and resumes execution after

the loop.

  1. What is the output of the following code?

python

for i in range(1, 6, 2):

print(i, end=" ")

A) 1 2 3 4 5

B) 1 3 5

C) 2 4 6

D) 1 3 5 7

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.

  1. Which of the following correctly checks if a number n is

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 <=

  1. range(10,20) excludes 20, so it's not inclusive of 20.

  2. What is the output of print(not (5 > 3) or (2 == 2))?

  3. Fals

e

  1. Tru

e

  1. Non

e

  1. Error Answer: B. True Explanation: (5 > 3) is True, so not True is

False.(2 == 2) is True. False or True evaluates to True.

  1. Which loop is guaranteed to execute at least once? A) forloop

B) while loop C) do-whileloop (Python does not have one)

  1. none of the above Answer: D. none of the above Explanation:

Python has no do-while loop. Both forand while loops check condi-

tions before the first iteration, so they may execute zero times.

  1. What is the value of xafter the following? python

x = 5 if x: x = 10

break

print(i, end=" ")

A) 0

B) 0 1

C) 0 1 2

D)No output Answer: A. 0 Explanation: When i = 0, condition false, print

  1. When i = 1, i == 1 is True, break exits the loop immediately without

printing 1 or further values.

E) How many times will "Hello"be printed? python i

= 0 while i < 5: print("Hello") i += 2

F) 2

G) 3

H) 4

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.

  1. Which expression evaluates to Trueif age is NOT between 18 and

65 inclusive? A) age < 18 or age > 65 B) not (18 <= age <= 65)

  1. both A and B D) age not in range(18,66) Answer: C. both A and B Ex-

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.

  1. What is the output of the following nested loop? python for i in

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)

A) 7

B) 12 C)

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)

A) 10

B) 20

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.

  1. What is the output?

python def func(x, y=2,

z=3): return x + y + z

print(func(1, z=4))

  1. Error Answer: B. 7 Explanation: x=1 (positional), yuses default 2, z

is overridden to 4. Sum = 1+2+4 = 7.

  1. Which of the following is a valid way to call a function defined as-

def multiply(a, b):? A) multiply(2)(3) B) multiply(2, 3) C) multiply(a=2,

b=3)

  1. Both B and C Answer: D. Both B and C Explanation: You can call us-

ing positional arguments (multiply(2,3)) or keyword arguments (multi-

ply(a=2,b=3)).

  1. What is the scope of a variable defined inside a function?
  2. Globa

l

  1. Local to that function
  2. Enclosing function only if nested
  3. Both B and C Answer: D. Both B and C Explanation: A variable de-

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).

  1. What will the following code print?

python def outer(): x = "local" def inner():

nonlocal x x = "nonlocal" inner() print(x)

outer() A) local B) nonlocal