Docsity

D335 INTRODUCTION TO PROGRAMMING IN PYTHON PRE-ASSESSMENT & PERFORMANCE ASSESSMENT Q&A, Exams of Programming Languages

Toggle sidebar
bg1
Page 1 of 41
D335 INTRODUCTION TO PROGRAMMING IN PYTHON
PRE-ASSESSMENT & PERFORMANCE ASSESSMENT
PRACTICE EXAM 2026/2027 COMPLETE (65) CURRENT
TESTING QUESTIONS AND CORRECT ANSWERS WITH
DETAILED RATIONALES.
PYTHON
Prepare for the D335 Introduction to Programming in Python Pre-Assessment &
Performance Assessment with a focused practice resource designed to reinforce
essential Python programming concepts. It supports review of topics such as
variables, data types, control flow, functions, loops, lists, and problem-solving
techniques. The resource can help you assess your understanding, build confidence,
and identify areas that need additional practice before completing the assessments.
This resource is best suited for WGU D335 students preparing for the Pre-Assessment
and Performance Assessment in Introduction to Programming in Python.
MULTIPLE CHOICE.
SECTION 1: MULTIPLE CHOICE QUESTIONS
Python Fundamentals & Data Types (Questions 1-15)
1. What is Python primarily classified as?
a) A compiled, statically typed language
b) A markup language
c) A low-level machine language
d) An interpreted, high-level, general-purpose programming language
e) A hardware description language
Answer: d) An interpreted, high-level, general-purpose programming
language
Rationale: Python is an interpreted language, meaning code is executed line
by line by the Python interpreter. It is high-level because it abstracts away
memory management and hardware details, and general-purpose because it
supports web development, data science, automation, AI, and more.
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

Partial preview of the text

Download D335 INTRODUCTION TO PROGRAMMING IN PYTHON PRE-ASSESSMENT & PERFORMANCE ASSESSMENT Q&A and more Exams Programming Languages in PDF only on Docsity!

D335 INTRODUCTION TO PROGRAMMING IN PYTHON

PRE-ASSESSMENT & PERFORMANCE ASSESSMENT

PRACTICE EXAM 2026/2027 COMPLETE ( 65 ) CURRENT

TESTING QUESTIONS AND CORRECT ANSWERS WITH

DETAILED RATIONALES.

PYTHON

Prepare for the D335 Introduction to Programming in Python Pre-Assessment & Performance Assessment with a focused practice resource designed to reinforce essential Python programming concepts. It supports review of topics such as variables, data types, control flow, functions, loops, lists, and problem-solving techniques. The resource can help you assess your understanding, build confidence, and identify areas that need additional practice before completing the assessments. This resource is best suited for WGU D335 students preparing for the Pre-Assessment and Performance Assessment in Introduction to Programming in Python. MULTIPLE CHOICE. SECTION 1: MULTIPLE CHOICE QUESTIONS Python Fundamentals & Data Types (Questions 1-15)

1. What is Python primarily classified as? a) A compiled, statically typed language b) A markup language c) A low-level machine language d) An interpreted, high-level, general-purpose programming language e) A hardware description language Answer: d) An interpreted, high-level, general-purpose programming language Rationale: Python is an interpreted language, meaning code is executed line by line by the Python interpreter. It is high-level because it abstracts away memory management and hardware details, and general-purpose because it supports web development, data science, automation, AI, and more.

2. Which symbol is used to write a single-line comment in Python? a) // b) /* c) # d) -- e) $$ Answer: c) # Rationale: In Python, the hash symbol # begins a single-line comment. Everything after # on that line is ignored by the interpreter. // is used in languages like JavaScript and C++. 3. What will print(type(5)) output? a) b) c) d) e) Answer: c) Rationale: The integer literal 5 belongs to the int class in Python. type() returns the data type of a value, and Python uses as its representation for integers. 4. Which of the following is a valid Python variable name? a) 2variable b) my-variable c) class d) my_variable e) my variable Answer: d) my_variable Rationale: Python variable names must begin with a letter or underscore, followed by letters, digits, or underscores. 2variable starts with a digit, my- variable contains a hyphen, class is a reserved keyword, and my variable contains a space.

returning a float. The result is 3.3333333333333335 due to floating-point representation.

8. What is the output of print(10 // 3)? a) 3 b) 3. c) 3. d) 4 e) Error Answer: a) 3 Rationale: The // operator performs floor division, which returns the integer quotient, discarding any remainder. 10 // 3 equals 3. 9. What is the output of print(10 % 3)? a) 3 b) 1 c) 0 d) 3. e) Error Answer: b) 1 Rationale: The % operator is the modulo operator, which returns the remainder of the division. 10 % 3 equals 1. 10. What will print(3 + 2.5) output? a) 5 b) 5. c) 6 d) Error Answer: b) 5. Rationale: Python automatically performs implicit type conversion. The integer 3 is converted to a float to perform the addition, resulting in a float value of 5.5.

11. What will print("Hello" + " " + "World") output? a) HelloWorld b) Hello World c) "Hello World" d) Error Answer: b) Hello World Rationale: The + operator concatenates strings. "Hello" + " " + "World" results in the string "Hello World". 12. What does the input() function return in Python? a) An integer b) A float c) A string d) A boolean e) A list Answer: c) A string Rationale: The input() function always returns the user's input as a string. You must use int() or float() to convert it to a numeric type if needed. 13. Which function converts a string to an integer? a) str() b) char() c) int() d) float() e) bool() Answer: c) int() Rationale: The int() function converts a string or number to an integer. str() converts to a string, and float() converts to a float. 14. What is the data type of the variable x after the following code is executed?

Rationale: A standard while loop checks its condition before executing. If the condition is initially True, it will execute. However, a standard while loop can potentially execute zero times. Python does not have a do-while loop, but a while True: loop will run at least until a break statement is encountered.

17. What is the output of the following code? python for i in range(3): print(i, end=" ") a) 0 1 2 b) 1 2 3 c) 0 1 2 3 d) 1 2 Answer: a) 0 1 2 Rationale: range(3) generates numbers 0, 1, 2. The end=" " parameter keeps the output on the same line with spaces. 18. What is the output of the following code? python x = 10 if x > 5: print("A") else: print("B") a) A b) B c) AB d) Error

Answer: a) A Rationale: Since 10 > 5 is True, the if block executes and prints "A".

19. What is the output of the following code? python x = 3 if x % 2 == 0: print("Even") else: print("Odd") a) Even b) Odd c) Error d) None Answer: b) Odd Rationale: 3 % 2 equals 1, which is not equal to 0, so the else block executes and prints "Odd". 20. What is the output of the following code? python count = 0 while count < 3: print(count) count += 1 a) 0 1 2 b) 1 2 3 c) 0 1 2 3

a) A b) B c) C d) Error Answer: b) B Rationale: x > 10 is False, but x > 3 is True, so the elif block executes and prints "B".

23. What is the output of the following code? python for i in range(5): if i == 3: break print(i, end=" ") a) 0 1 2 b) 0 1 2 3 c) 0 1 2 3 4 d) 3 4 Answer: a) 0 1 2 Rationale: The loop prints 0, 1, 2. When i becomes 3, the break statement exits the loop before printing 3. 24. What is the output of the following code? python for i in range(5): if i == 2: continue print(i, end=" ")

a) 0 1 2 3 4 b) 0 1 3 4 c) 0 1 2 d) 2 3 4 Answer: b) 0 1 3 4 Rationale: The continue statement skips the rest of the current iteration. When i == 2, the print statement is skipped, so 2 is not printed.

25. What is the output of the following code? python x = 0 while x < 5: x += 1 if x == 3: continue print(x, end=" ") a) 1 2 3 4 5 b) 1 2 4 5 c) 0 1 2 4 5 d) 1 2 3 4 Answer: b) 1 2 4 5 Rationale: The loop increments x to 1, 2, 3, 4, 5. When x == 3, the continue skips the print statement, so 3 is not printed. **Functions (Questions 26-30)

  1. What is the output of the following code?** python def my_function():

greet("Alice") a) Hello, World! Hello, Alice! b) Hello,! Hello, Alice! c) Hello, World! Hello,! d) Error Answer: a) Hello, World! Hello, Alice! Rationale: The parameter name has a default value of "World". When called without an argument, it uses the default. When called with "Alice", it uses the provided argument.

29. What is the output of the following code? python def outer(): x = 10 def inner(): print(x) inner() outer() a) 10 b) None c) Error d) x Answer: a) 10 Rationale: The inner function inner() has access to variables in the enclosing function outer(), so it can print x. 30. What is the output of the following code? python

def multiply(a, b): return a * b result = multiply(2, 3) print(result) a) 2 b) 3 c) 5 d) 6 Answer: d) 6 Rationale: The function multiply returns the product of its two arguments. multiply(2, 3) returns 6. Lists & Data Structures (Questions 31-40)

31. What is the output of the following code? python my_list = [1, 2, 3, 4, 5] print(my_list[2]) a) 1 b) 2 c) 3 d) 4 Answer: c) 3 Rationale: Python lists are zero-indexed. my_list[2] accesses the third element, which is 3. 32. What is the output of the following code? python my_list = [1, 2, 3, 4, 5]

my_list.append(4) print(my_list) a) [1, 2, 3] b) [1, 2, 3, 4] c) [4, 1, 2, 3] d) Error Answer: b) [1, 2, 3, 4] Rationale: The append() method adds an element to the end of the list.

36. What is the output of the following code? python my_list = [1, 2, 3] my_list.insert(1, 4) print(my_list) a) [1, 2, 3, 4] b) [1, 4, 2, 3] c) [4, 1, 2, 3] d) [1, 2, 4, 3] Answer: b) [1, 4, 2, 3] Rationale: insert(1, 4) inserts the value 4 at index 1, shifting the existing elements to the right. 37. What is the output of the following code? python my_list = [1, 2, 3, 4] my_list.remove(3) print(my_list)

a) [1, 2, 4] b) [1, 2, 3, 4] c) [1, 2, 3] d) Error Answer: a) [1, 2, 4] Rationale: The remove() method removes the first occurrence of the specified value (3).

38. What is the output of the following code? python my_dict = {"name": "Alice", "age": 30} print(my_dict["name"]) a) Alice b) 30 c) name d) Error Answer: a) Alice Rationale: Dictionaries are accessed using keys. my_dict["name"] returns the value associated with the key "name", which is "Alice". 39. What is the output of the following code? python my_dict = {"a": 1, "b": 2, "c": 3} print(my_dict.get("d", 0)) a) 0 b) None c) d d) Error Answer: a) 0

python num1 = 0. num2 = 0. result = num1 + num print(f'Sum: {result}') c) python from decimal import Decimal num1 = 0. num2 = 0. result = Decimal(num1) + Decimal(num2) print(f'Sum: {result}') d) python from decimal import Decimal num1 = Decimal('0.1') num2 = Decimal('0.2') result = num1 * num print(f'Accurate product using decimal: {result}') Answer: a) python from decimal import Decimal num1 = Decimal('0.1') num2 = Decimal('0.2')

result = num1 + num print(result) Rationale: The decimal module provides exact decimal arithmetic. To avoid precision errors, you should create Decimal objects from strings. Option a correctly adds two Decimal objects created from strings.

42. What is the primary purpose of the pickle module in Python? a) To read and write CSV files b) To serialize and deserialize Python objects c) To perform mathematical operations d) To manage file input and output Answer: b) To serialize and deserialize Python objects Rationale: The pickle module converts Python objects into a byte stream for storage or transmission (serialization) and can reconstruct the objects from the byte stream (deserialization). 43. Which of the following statements about the pickle module is FALSE? a) The Python Standard Library's pickle module can serialize objects into the data formats of many popular programming languages. b) Pickle has potential security issues. c) If you write your own pickling and de-pickling code, pickling can be secure. d) All of the above statements are true. Answer: a) The Python Standard Library's pickle module can serialize objects into the data formats of many popular programming languages. Rationale: The pickle module is Python-specific and does not serialize objects into formats used by other programming languages. JSON or XML are used for cross-language serialization. Pickle does have security issues (b), and custom pickling code can be made more secure (c). 44. Which of the following statements about Python modules is FALSE? a) Consider a module to be the same as a code library.