Docsity

WGU E010 FOUNDATIONS OF PROGRAMMING (PYTHON) OA 2026 FINAL EXAM COMPLETE (50) CURRENT TEST, Exams of Semantics of Programming Languages

Toggle sidebar
bg1
Page 1 of 23
WGU E010 FOUNDATIONS OF
PROGRAMMING (PYTHON) OA 2026 FINAL
EXAM COMPLETE (50) CURRENT TESTING
QUESTIONS AND CORRECT ANSWERS WITH
DETAILED EXPLANATIONS|GUARANTEED
PASS.
PYTHON
Ace the WGU E010 Foundations of Programming (Python) OA Final
Exam with practice questions covering Python data types, control
structures, functions, data structures, string operations, and
common built-in functions. 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.
Data Types & Type Conversion
1. What is the output of the following code?
python
print(type(10 / 2))
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17

Partial preview of the text

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

WGU E010 FOUNDATIONS OF

PROGRAMMING (PYTHON) OA 2026 FINAL

EXAM COMPLETE (50) CURRENT TESTING

QUESTIONS AND CORRECT ANSWERS WITH

DETAILED EXPLANATIONS|GUARANTEED

PASS.

PYTHON

Ace the WGU E010 Foundations of Programming (Python) OA Final

Exam with practice questions covering Python data types, control

structures, functions, data structures, string operations, and

common built-in functions. 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.

Data Types & Type Conversion

1. What is the output of the following code?

python

print(type(10 / 2))

A)

B)

C)

D)

Answer: B.

Explanation: In Python, the / operator always returns a float,

even when the two numbers divide evenly. 10 / 2 evaluates

to 5.0, which is a float.

2. Which of the following data types is immutable? 3. list 4. dict 5. set 6. tuple Answer: D. tuple Explanation: Tuples cannot be changed after

they are created. Lists, dictionaries, and sets are mutable.

7. What is the result of print(10 // 3)?

11. 3.0 Answer: B. 3 Explanation: The // operator performs floor division

(integer division). It returns the quotient without the remainder, so

10 // 3 evaluates to 3.

Indexing, Slicing & String Methods

7. What is the output of print("a" + "b" * 2)? A) ab B)

abb C) bab

8. Error Answer: B. abb Explanation: Multiplication (*) has higher prece-

dence than addition (+). First, "b" is repeated twice ("bb"), then concate-

nated with "a".

8. Given x = "Hello" , what does print(x[1]) output? A) H B) e C) l D) o An-

swer: B. e Explanation: Strings are zero-indexed. Index 0 → H, index 1

→e.

9. What is the output of print("Python"[2:5])? A) Pyt B)

tho C) yth D) hon

Answer: B. tho

Explanation: Slicing [2:5] takes characters from index 2 up to

(but not including) index 5.

Indices: P0 y1 t2 h3 o4 n5 → slice "tho".

Collections: Lists, Dictionaries & Tuples

10. What does print(x[-1]) output if x = [1, 2, 3]?

14. Error Answer: C. 3 Explanation: Negative indexing starts from the

end of the sequence. -1 refers to the last element.

15. How do you write a single-line comment in Python? A) // B) # C)

D) """ Answer: B. # Explanation: The hash symbol #begins a

comment. Everything after it on that line is ignored by the interpreter.

12. What does the append() method do when called on a list? 13. Removes the last item

C) [4]

D)Error Answer: B. [1, 2, 3] Explanation: a[:] creates a shallow copy of a.

Changes to the copy do not affect the original list.

E) Which of the following creates a list comprehension? A)[x for x in

range(5)] B)(x for x in range(5)) C) {x for x in range(5)} D) x for x in range(5)

Answer: A. [x for x in range(5)] Explanation: List comprehensions are

enclosed in square brackets[]. Parentheses create a generator expres-

sion, curly braces create a set comprehension.

F) What does the range(3) function produce? A)[0, 1, 2] B) [1, 2, 3] C) [0,

1, 2, 3] D) (0, 1, 2) Answer: A. [0, 1, 2] Explanation: range(3) generates a

sequence of integers starting from 0 up to (but not including) 3. In

Python 3, range() returns an iterable, but when printed or converted to a

list, it produces[0, 1, 2].

Loops & Conditionals

17. Which loop is most appropriate when the number of iterations

is not known beforehand? A) forloop B) while loop

18. nested loop D) foreach loop Answer: B. while loop Explanation: A

while loop continues as long as a condition remains true. It is ideal

when you do not know how many times the loop should run.

19. What does the break statement do? 20. Skips one iteration and continues 21. Exits the loop entirely 22. Restarts the loop 23. Raises an exception Answer: B. Exits the loop entirely Explanation:

break immediately terminates the nearest enclosing loop (for or while).

Program execution resumes after the loop.

24. Which keyword is used to define a function in Python? A) function

B)def C) define D) func

21. Which keyword is used to handle exceptions in Python?

A) catch

B) try

C) error

D) exceptify

Answer: B. try

Explanation: Python uses try/except blocks to handle

exceptions. Code that may raise an exception is placed in

a try block, and handling code goes in the

corresponding except block.

Operators & Expressions

22. Which operator is not valid in Python 3? A) // B) % C) <> D) ** An-

swer: C. <> Explanation: In Python 2, <>was used as a not-equal oper-

ator. Python 3 uses!=exclusively. <> is invalid in Python 3.

23. What is the output of print(2 ** 3)?

Object-Oriented Concepts

24. Which keyword is used to define a class in Python?

A) function

B) class

C) object

D) struct

Answer: B. class

Explanation: Classes are defined using the class keyword,

followed by the class name and a colon. The class body

contains methods and attributes.

List & String Operations

25. What is the output of the following code?

python

sports = ["basketball", "baseball", "football", "soccer", "tennis"]

last = sports[-3:]

C) 9

D) 5 Answer: B. 8 Explanation: The ** operator raises the left operand to

the power of the right operand. 2³= 8.

Answer: B. yth

Explanation: [1:4] takes characters from index 1 up to but not

including index 4. P0 y1 t2 h3 o4 → "yth".

Advanced/Exam-Style Questions

28. Which of the following statements correctly describes how

Python executes code?

29. Python compiles code into machine language before execu-

tion.

30. Python is an interpreted language; it reads and executes line by line. 31. Python uses a Just-In-Time (JIT) compiler exclusively. 32. Python is a fully compiled language like C++. Answer: B. Python is an

interpreted language; it reads and executes line by line. Explana-

tion: Python is an interpreted, high-level programming language. It com-

piles source code into bytecode, which is then executed by the Python

Virtual Machine (PVM).

33. Which of the following is a correct way to extract the last three

items from a list called data without modifying data? A)data.pop(3)

B)data[-3:] C) data[:-3] D) data.clear()

Answer: B. data[-3:]

Explanation: Slice notation [-3:] creates a new list containing

the last three elements. It does not alter the original list.

30. Given x = "Hello" , what will print(x[-1]) output?

A) H

B) e

C) l

D) o

Answer: D. o

Explanation: Negative indices count from the end of a string. -

1 always returns the last character, which is "o".

More Questions

31. What is the output of the following code?

python

print(type("Hello" * 3))

A)

B)

C)

D)

Answer: C.

Explanation: Multiplying a string by an integer repeats the

string. The result is still a string.

C) int("3.14")

D) float("5.0")

Answer: C. int("3.14")

Explanation: The string must represent a valid integer

literal. "3.14" cannot be converted directly to an integer because

of the decimal point.

35. What is the output of the following code? python print("Hello" +

"World") A) HelloWorld B) Hello World C) Hello+World D) "Hello" +

"World" Answer: A. HelloWorld Explanation: The + operator concate-

nates strings. No space is added unless explicitly included.

36. Which of the following statements about range(5, 10, 2) is correct? 37. It generates numbers 5, 6, 7, 8, 9 38. It generates numbers 5, 7, 9 39. It generates numbers 5, 7, 9, 11 40. It generates numbers 5, 10, 15 Answer: B. It generates numbers 5,

7, 9 Explanation: The first argument is the start (5), the second is

the stop (10 – not included), and the third is the step (2). So it

yields 5, 7, 9.

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

print(3 == 3.0)

38. Tru

e

39. Fals

e

40. Er-

ror

41. None Answer: A. True Explanation: The == operator compares val-

ues, not types. Since 3and 3.0 represent the same numeric value, the

comparison returns True.

42. Which of the following correctly defines a Python function

that returns the square of a number? A)def square(x): return x * x

B) function square(x) { return x * x; } C) def square(x) { return x * x } D)

square(x): return x * x Answer: A. def square(x): return x * x Expla-

nation: Python uses the def keyword, a colon, and indentation to

define functions. Braces are not used.

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

C)Error

D)None Answer: B. False Explanation: The and operator returns True only

if both conditions are True. Here, 10 > 5 is True, but 5 > 10 is False, so the

overall expression isFalse.

E) Which of the following correctly reads a line of text from the user

and strips the trailing newline? A) input().strip() B) input().split() C) in-

put().read() D) input().stripnewline() Answer: A. input().strip() Explana-

tion: input() returns the user’s input as a string, including a trailing new-

line. The.strip()method removes leading/trailing whitespace, including

the newline character.

F) What is the output of the following code? python

print(5 * "Hi") A) HiHiHiHiHi B) Hi repeated 5 times (Hi-

HiHiHiHi) C) 5*Hi D) 5 Hi

Answer: A. HiHiHiHiHi

Explanation: Multiplying a string by an integer repeats the

string. 5 * "Hi" produces "HiHiHiHiHi".

44. Which of the following statements about Python’s None is true? A)

Noneis the same as 0 B) Noneis the same as False C) None represents a

null value or no value D) None is a reserved keyword for a missing argu-

ment Answer: C. None represents a null value or no value Explana-

tion: None is a special constant used to denote the absence of a value

or a null value. It is not equivalent to 0, False, or any empty container.

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

print(len("Python"))

49. Error Answer: B. 6 Explanation: The len() function returns the

number of characters in a string. "Python" has 6 letters.