Docsity

WGU E010 FOUNDATIONS OF PROGRAMMING PYTHON OBJECTIVE ASSESSMENT FINAL EXAM, Exams of Programming Languages

Toggle sidebar
bg1
1
WGU E010 FOUNDATIONS OF
PROGRAMMING PYTHON OBJECTIVE
ASSESSMENT FINAL EXAM 150
APPLICATION LEVEL SCENARIO
BASED QUESTIONS WITH ANSWERS
AND DETAILED RATIONALES
Subject: WGU E010 Foundations of Programming (Python) – Python
Syntax, Data Types, Control Flow, Functions, Data Structures, File
I/O, Exception Handling, Object-Oriented Programming,
Comprehensions, Generators, and Debugging
Description: This examination is designed for candidates preparing
for the WGU E010 Objective Assessment in Foundations of
Programming (Python). It assesses applied knowledge of Python
syntax and structure, variables and data types, operators and
expressions, conditional statements and loops, functions and
parameter passing, scope and recursion, lists, tuples, dictionaries, and
sets, string manipulation and slicing, file input and output, exception
handling, object-oriented programming with classes and inheritance,
comprehensions, generators, and debugging. Questions are scenario
based and require code tracing, output prediction, and critical decision
making consistent with the competencies assessed in the WGU E010
objective assessment. The exam is structured in three sections of fifty
questions each, with four options per question and detailed rationales
for every correct answer.
SECTION 1: Questions 1 to 50
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

Partial preview of the text

Download WGU E010 FOUNDATIONS OF PROGRAMMING PYTHON OBJECTIVE ASSESSMENT FINAL EXAM and more Exams Programming Languages in PDF only on Docsity!

WGU E010 FOUNDATIONS OF

PROGRAMMING PYTHON OBJECTIVE

ASSESSMENT FINAL EXAM 150

APPLICATION LEVEL SCENARIO

BASED QUESTIONS WITH ANSWERS

AND DETAILED RATIONALES

Subject: WGU E010 Foundations of Programming (Python) – Python Syntax, Data Types, Control Flow, Functions, Data Structures, File I/O, Exception Handling, Object-Oriented Programming, Comprehensions, Generators, and Debugging Description: This examination is designed for candidates preparing for the WGU E010 Objective Assessment in Foundations of Programming (Python). It assesses applied knowledge of Python syntax and structure, variables and data types, operators and expressions, conditional statements and loops, functions and parameter passing, scope and recursion, lists, tuples, dictionaries, and sets, string manipulation and slicing, file input and output, exception handling, object-oriented programming with classes and inheritance, comprehensions, generators, and debugging. Questions are scenario based and require code tracing, output prediction, and critical decision making consistent with the competencies assessed in the WGU E objective assessment. The exam is structured in three sections of fifty questions each, with four options per question and detailed rationales for every correct answer. SECTION 1: Questions 1 to 50

  1. A developer needs to store a collection of employee IDs that must remain in the order they are entered and must allow items to be added and removed during execution. Which built in Python data type best satisfies these requirements? A) Tuple B) Dictionary C) List D) Set Answer: C Rationale: Lists are ordered and mutable, so they maintain insertion order and support addition and removal of items. Tuples are immutable, sets are unordered, and dictionaries store key value pairs rather than sequential items.
  2. Evaluate the following expression and determine the final value assigned to result. result = 17 // 4 + 5 % 2 A) 5 B) 5. C) 4 D) 6 Answer: A Rationale: Floor division 17 // 4 yields 4. The modulo operator 5 % 2 yields 1. Adding the two results gives 4 + 1 = 5.
  3. A programmer writes the following code. x = "WGU"

B) "ght" C) "ghtO" D) "hto" Answer: B Rationale: Slicing is inclusive of the start index and exclusive of the end index. Index 2 is g, index 3 is h, and index 4 is t, while index 5 (O) is excluded.

  1. A developer needs to iterate over a list and access both the index position and the corresponding value during each iteration. Which built in function should be used? A) zip() B) range() C) enumerate() D) map() Answer: C Rationale: enumerate() returns both the index and the value during iteration over a sequence.
  2. A student writes the expression 3 * "ab". What will Python produce? A) "ababab" B) "ab3" C) An error D) "aaabbb" Answer: A

Rationale: Multiplying a string by an integer repeats the string that many times, concatenating it three times to yield "ababab".

  1. An analyst needs to determine the remainder of 10 divided by 3. Which operator should be used, and what is the result? A) The / operator; result is 3. B) The // operator; result is 3 C) The % operator; result is 1 D) The ** operator; result is 9 Answer: C Rationale: The modulo operator % returns the remainder of division. 10 % 3 yields 1.
  2. A programmer needs to create a variable that cannot be modified after its initial assignment. Which data type satisfies this requirement? A) List B) Dictionary C) Set D) Tuple Answer: D Rationale: Tuples are immutable sequences, meaning their contents cannot be altered after creation. Lists, dictionaries, and sets are mutable.
  3. An instructor asks a student to verify the type of the expression 10 / 2. The student runs print(type(10 / 2)). What output should the student expect?
  1. A developer is writing a function to calculate the factorial of a non negative integer. Which recursive implementation is correct? A) def factorial(n): return n * factorial(n - 1) if n > 1 else 1 B) def factorial(n): return n * factorial(n) if n > 1 else 1 C) def factorial(n): return factorial(n - 1) if n > 1 else 0 D) def factorial(n): return n + factorial(n - 1) if n > 1 else 1 Answer: A Rationale: A correct recursive factorial multiplies n by the factorial of n minus 1, with a base case returning 1 when n is 1 or 0.
  2. A data analyst needs to combine multiple CSV files into a single list of dictionaries, where each dictionary represents a row and the files share the same columns. Which approach is most efficient and Pythonic? A) Opening each file in a nested loop and manually parsing commas B) Using the csv module with csv.DictReader in a loop over the file paths C) Reading each file as a single string and splitting on newlines only D) Using a single call to open() without iterating over the files Answer: B Rationale: csv.DictReader maps each row to a dictionary using the header row, and iterating over file paths with a loop is the standard Pythonic approach for this task.
  3. What does the input() function return in Python 3? A) An integer B) A string

C) A float D) A boolean Answer: B Rationale: input() always returns a string, and the programmer must convert it to the desired type if needed.

  1. A developer wants to repeat a block of code a known number of times. Which loop construct is most appropriate? A) while loop B) for loop with range() C) do while loop D) recursive function Answer: B Rationale: A for loop with range() is best when the number of iterations is known in advance.
  2. What is the output of the following code? print(15 // 4) A) 3. B) 3 C) 4 D) 3. Answer: B Rationale: The floor division operator // returns the integer quotient, discarding the remainder. 15 // 4 equals 3.

D) {4, 5}

Answer: B Rationale: The & operator performs set intersection, returning elements common to both sets, which is {3}.

  1. A programmer wants to create a new list containing the squares of all even numbers from an existing list numbers. Which comprehension achieves this? A) [x ** 2 for x in numbers if x % 2 == 0] B) [x ** 2 for x in numbers if x % 2 != 0] C) [x for x in numbers if x % 2 == 0] D) [x ** 2 for x in numbers] Answer: A Rationale: The comprehension filters even numbers with if x % 2 == 0 and squares each selected element.
  2. What is the purpose of the try and except blocks in Python? A) To define a function B) To handle exceptions and prevent program crashes C) To create a loop D) To import a module Answer: B Rationale: try and except blocks allow the program to catch and handle exceptions gracefully rather than terminating with an error.
  3. A developer writes the following code.

def greet(name="World"): return "Hello, " + name print(greet()) print(greet("Alice")) What is the output? A) Hello, World Hello, Alice B) Hello, Hello, Alice C) Hello, name Hello, Alice D) An error occurs Answer: A Rationale: The default parameter value "World" is used when no argument is provided, and "Alice" is used when provided.

  1. Which of the following is a mutable data type in Python? A) String B) Tuple C) List D) Integer Answer: C Rationale: Lists are mutable and can be modified after creation, while strings, tuples, and integers are immutable.

Rationale: The with statement uses a context manager to guarantee that the file is closed even if an exception occurs.

  1. A developer defines a class Dog with a method bark. What is the correct way to create an instance of Dog? A) Dog = new Dog() B) my_dog = Dog() C) my_dog = Dog D) my_dog = new Dog Answer: B Rationale: Instantiating a class in Python uses the class name followed by parentheses, such as my_dog = Dog().
  2. What does the self parameter represent in an instance method? A) The class itself B) The current instance of the class C) A global variable D) The parent class Answer: B Rationale: self refers to the instance on which the method is called, allowing access to instance attributes and methods.
  3. A developer wants to create a subclass that inherits from a parent class. Which syntax is correct? A) class Child(Parent): B) class Child extends Parent:

C) class Child inherits Parent: D) class Child: Parent Answer: A Rationale: Python uses parentheses after the class name to indicate inheritance, such as class Child(Parent):.

  1. What is the output of the following code? def add(a, b=2): return a + b print(add(3)) print(add(3, 4)) A) 5 7 B) 5 5 C) 7 7 D) An error occurs Answer: A Rationale: The default value b=2 is used when only one argument is provided, yielding 3 + 2 = 5. When two arguments are provided, 3 + 4 = 7.
  2. Which method removes and returns the last item from a list? A) pop() B) remove()
  1. A developer wants to concatenate two lists. Which operator is used? A) & B) | C) + D) * Answer: C Rationale: The + operator concatenates two lists into a new list.
  2. What is the result of the following code? print("Hello"[1:4]) A) "Hell" B) "ello" C) "ell" D) "Hello" Answer: C Rationale: Slicing from index 1 up to but not including index 4 returns characters at indices 1, 2, and 3, which are e, l, and l, yielding "ell".
  3. A developer needs to sort a list of numbers in ascending order. Which method should be used? A) list.sort() B) list.order() C) list.arrange() D) list.sequence()

Answer: A Rationale: list.sort() sorts the list in place in ascending order by default.

  1. What is the output of the following code? x = 5 if x > 3: print("A") elif x > 1: print("B") else: print("C") A) A B) B C) C D) Nothing is printed Answer: A Rationale: The first condition x > 3 is true, so A is printed and the elif and else branches are skipped.
  2. A developer wants to create a dictionary from two lists, one of keys and one of values. Which function is most appropriate? A) zip() combined with dict() B) map() combined with list() C) filter() combined with dict() D) enumerate() combined with dict()

B) [1, 2, 3, 4]

C) [0, 1, 2, 3, 4]

D) [2, 3, 4, 5]

Answer: B Rationale: range(1, 5) generates numbers starting at 1 up to but not including 5, yielding [1, 2, 3, 4].

  1. A developer needs to convert a string containing a whole number into an integer. Which function should be used? A) str() B) float() C) int() D) bool() Answer: C Rationale: int() converts a string that represents a whole number into an integer.
  2. What happens if int("3.14") is executed? A) It returns 3 B) It returns 3. C) It raises a ValueError D) It returns None Answer: C Rationale: int() cannot convert a string containing a decimal point directly and raises a ValueError.
  1. A developer wants to define a function that accepts any number of positional arguments. Which parameter syntax should be used? A) def func(args): B) def func(args): C) def func(*args): D) def func(args[]): Answer: B Rationale: The *args syntax allows a function to accept any number of positional arguments as a tuple.
  2. What is the purpose of the **kwargs parameter in a function definition? A) To accept any number of positional arguments B) To accept any number of keyword arguments as a dictionary C) To define a global variable D) To handle exceptions Answer: B Rationale: **kwargs collects arbitrary keyword arguments into a dictionary.
  3. A developer wants to create a shallow copy of a list. Which approach is correct? A) new_list = old_list B) new_list = old_list[:] C) new_list = old_list.copy D) new_list = old_list.clone()